Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-4518

Battery "level" is not calculated correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Later
    • 2.9.0
    • None
    • cordova-android
    • None

    Description

      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:

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

      Attachments

        Issue Links

          Activity

            People

              bowserj Joey Robert Bowser
              dinglemouse Peter
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: