react-native-device-battery icon indicating copy to clipboard operation
react-native-device-battery copied to clipboard

(evaluating '_reactNativeDeviceBattery2.default.addListener()')

Open Madhukanth opened this issue 7 years ago • 18 comments

DeviceBattery.addListener() alone is causing error

undefined is not a function(evaluating '_reactNativeDeviceBattery2.default.addListener()')

Please help me to solve this...

Madhukanth avatar Nov 28 '17 11:11 Madhukanth

Could you share a snippet of what your import statement looks like?

atticoos avatar Nov 29 '17 22:11 atticoos

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.

Madhukanth avatar Nov 30 '17 03:11 Madhukanth

Thanks, we’ll try to reproduce this on our end.

atticoos avatar Nov 30 '17 04:11 atticoos

It's ok...Please make the necessary updates...

Thank you

Madhukanth avatar Nov 30 '17 04:11 Madhukanth

@Madhukanth Can you please provide more info (RN version & platform) regarding this issue that you're facing?

yinghang avatar Nov 30 '17 15:11 yinghang

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

battery.zip

Thank you.

Madhukanth avatar Dec 01 '17 05:12 Madhukanth

Sorry for the delay.

Madhukanth avatar Dec 01 '17 05:12 Madhukanth

@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.

yinghang avatar Dec 01 '17 15:12 yinghang

Thank you so much... I will look through it.

Thanks again.

Madhukanth avatar Dec 01 '17 15:12 Madhukanth

Sorry...It shows host key verification failed??

Madhukanth avatar Dec 01 '17 15:12 Madhukanth

Sorry, can you try this?

npm install https://github.com/robinpowered/react-native-device-battery.git#37f61a53fd2ca51ccfee90d6e4bf5676f6f2ddab

yinghang avatar Dec 01 '17 15:12 yinghang

Sure.I will try and report.

Thanks again...

Madhukanth avatar Dec 01 '17 15:12 Madhukanth

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???

Madhukanth avatar Dec 01 '17 16:12 Madhukanth

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.

Madhukanth avatar Dec 01 '17 17:12 Madhukanth

I will take a look and get back to you 😄

yinghang avatar Dec 01 '17 17:12 yinghang

Sure...Thank you

Madhukanth avatar Dec 02 '17 02:12 Madhukanth

I added this code to AndroidManifest.xml

After that app crashes when charging pluged out or pluged in..

Madhukanth avatar Dec 04 '17 06:12 Madhukanth

<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>

Madhukanth avatar Dec 04 '17 07:12 Madhukanth