Handset battery level

Is it possible to set the battery level in the Android application using the phone back?

thanks

+6
source share
2 answers

You can actually get the battery level on PhoneGap. If you want, you can register event listeners for the following events:

  • "batterystatus" is triggered whenever the battery level changes by 1% or is connected or disconnected.
  • "batterylow" is triggered when the minimum battery threshold is reached, that is 20%
  • "batterycritical" is triggered when a critical battery level is reached, that is 5%

For some reason, this did not appear on the docs site. I will have to fix it.

+5
source

To get the battery level and turn it on, use the code: -

//Battery Info document.addEventListener('batterystatus', batteryInfo, false); var level="Level: 50%"; var isPlugged="Plugged: Yes"; function batteryInfo(info){ level="Level: "+info.level+"%"; if(info.isPlugged){ isPlugged="Plugged: Yes"; }else{ isPlugged="Plugged: No"; } console.log("Level: " + info.level + " isPlugged: " + info.isPlugged); } 

To display information, use the level variable and isPlugged.

0
source

Source: https://habr.com/ru/post/901625/


All Articles