react-native-device-battery
react-native-device-battery copied to clipboard
(evaluating '_reactNativeDeviceBattery2.default.addListener()')
DeviceBattery.addListener() alone is causing error
undefined is not a function(evaluating '_reactNativeDeviceBattery2.default.addListener()')
Please help me to solve this...
Could you share a snippet of what your import statement looks like?
import DeviceBattery from 'react-native-device-battery';
This is my import statement.
DeviceBattery.getBatteryLevel(
) and DeviceBattery.isCharging()
is working.
But DeviceBattery.addListener()
is not working and showing the above error.
Thank you for your reply.
Thanks, we’ll try to reproduce this on our end.
It's ok...Please make the necessary updates...
Thank you
@Madhukanth Can you please provide more info (RN version & platform) regarding this issue that you're facing?
These are my configuration and versions.Please refer it, react-native-cli: 2.0.1 react-native: 0.50.4
Android 5.1 physical device
My PC is windows 8.1 32bit
gradle version: 2.14.1
Thank you.
Sorry for the delay.
@Madhukanth
I believe you can solve that issue by installing directly from this commit since we haven't published the updated version to npm.
Just do npm install git+ssh://[email protected]/robinpowered/react-native-device-battery.git#37f61a53fd2ca51ccfee90d6e4bf5676f6f2ddab
and you should be all set.
Let me know if that works.
Thank you so much... I will look through it.
Thanks again.
Sorry...It shows host key verification failed??
Sorry, can you try this?
npm install https://github.com/robinpowered/react-native-device-battery.git#37f61a53fd2ca51ccfee90d6e4bf5676f6f2ddab
Sure.I will try and report.
Thanks again...
This time there is no error... But in the console there is no output..
Do i need to get any permission for battery which i should include it in AndroidManifest.xml???
I have added permission too.. But still i have no output. The console doesn't shows anything. I downloaded the package from the link you gave.
import DeviceBattery from 'react-native-device-battery';
componentWillMount(){
const onBatteryStateChanged = state => console.log(state);
DeviceBattery.addListener(onBatteryStateChanged);
}
This is my code.
I will take a look and get back to you 😄
Sure...Thank you
I added this code to AndroidManifest.xml
After that app crashes when charging pluged out or pluged in..
<receiver android:name=".PowerConnectionReceiver"> <intent-filter> <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/> <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/> </intent-filter> </receiver>