Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Madhukanth opened this issue Nov 28, 2017 · 18 comments
Open

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

Madhukanth opened this issue Nov 28, 2017 · 18 comments
Assignees

Comments

@Madhukanth
Copy link

DeviceBattery.addListener() alone is causing error

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

Please help me to solve this...

@atticoos
Copy link
Contributor

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

@Madhukanth
Copy link
Author

Madhukanth commented Nov 30, 2017

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.

@atticoos
Copy link
Contributor

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

@Madhukanth
Copy link
Author

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

Thank you

@yinghang
Copy link
Contributor

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

@Madhukanth
Copy link
Author

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
Copy link
Author

Sorry for the delay.

@yinghang
Copy link
Contributor

yinghang commented Dec 1, 2017

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

@Madhukanth
Copy link
Author

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

Thanks again.

@Madhukanth
Copy link
Author

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

@yinghang
Copy link
Contributor

yinghang commented Dec 1, 2017

Sorry, can you try this?

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

@Madhukanth
Copy link
Author

Sure.I will try and report.

Thanks again...

@Madhukanth
Copy link
Author

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
Copy link
Author

Madhukanth commented Dec 1, 2017

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.

@yinghang
Copy link
Contributor

yinghang commented Dec 1, 2017

I will take a look and get back to you 😄

@Madhukanth
Copy link
Author

Sure...Thank you

@Madhukanth
Copy link
Author

I added this code to AndroidManifest.xml

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

@Madhukanth
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants