You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Peter (JIRA)" <ji...@apache.org> on 2013/08/07 03:54:47 UTC
[jira] [Created] (CB-4518) Battery "level" is not calculated
correctly
Peter created CB-4518:
-------------------------
Summary: Battery "level" is not calculated correctly
Key: CB-4518
URL: https://issues.apache.org/jira/browse/CB-4518
Project: Apache Cordova
Issue Type: Bug
Components: Android
Affects Versions: 2.9.0
Reporter: Peter
Assignee: Joe Bowser
Priority: Minor
The meaning of the Battery "level" in Cordova is a charge *percentage*.
Ref http://cordova.apache.org/docs/en/2.9.0/cordova_events_events.md.html#batterylow
But the Battery EXTRA_LEVEL is not a percentage. It's just a number in the range 0 to EXTRA_SCALE
Ref http://developer.android.com/reference/android/os/BatteryManager.html#EXTRA_LEVEL
So the battery level calculation should be something like:
{code}
int level = batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, 0);
int scale = batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, 100);
int percent = 100 * level / scale;
obj.put("level", percent);
{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira