12

How can I detect battery charging speed in android device? I can detect battery status using below code. but not charging speed.

IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
BatteryChangeReceiver receiver = new BatteryChangeReceiver(subscriber);
registerReceiver(receiver, filter);


public class BatteryChangeReceiver extends BroadcastReceiver {

    @Override public void onReceive(Context context, Intent intent) {
              // here I get all battery status.
    }
  }

I also refer this,this and this but cant find the way to check charging speed.

There is an app (Ampere) that displaying charging speed. enter image description here enter image description here How can I achieve this?

Thanks in advance.

5
  • Make a time and charging percentage combination.
    – Amy
    Aug 12, 2016 at 7:47
  • No, It will display as soon as I connect to the charger. If I connect to USB cable then is displaying slow charging and if wall charger and fast charging. Aug 12, 2016 at 8:01
  • I think you can find it in the dmesg log of the device. Aug 12, 2016 at 8:15
  • I added two other screenshots. Aug 12, 2016 at 8:30
  • Did you find any solution for that? Considering with now have super-fast charge @ 80W, the reported mA is incorrect (half of reality) and detecting charge type would be super-useful!
    – 3c71
    Aug 12, 2022 at 7:35

2 Answers 2

7
+25

Use the BatteryManager. It provides the property BATTERY_PROPERTY_CURRENT_AVERAGE, which gives you the average battery current in microamperes. Unfortunately, the time period over which this information is collected may differ from device to device. Negative values mean discharging, positive values mean the phone is charging.

Alternatively, you could use BATTERY_PROPERTY_CURRENT_NOW (it looks like Ampere is using this approach). It returns the instantaneous battery current. It may not be accurate, so calling this property a couple times and calculating the average seems like a good idea.

Example code:

BatteryManager batteryManager = (BatteryManager) Context.getSystemService(Context.BATTERY_SERVICE);
int averageCurrent = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE);
2
  • It is added in API 21. Can you provide the solution that also work in lower version.? Aug 16, 2016 at 6:50
  • Only phones that have a battery fuel gauge (source.android.com/devices/tech/power/device.html) can report back BATTERY_PROPERTY_CURRENT_AVERAGE. For example, Nexus 5 can only provide you with BATTERY_PROPERTY_CAPACITY.
    – Jehy
    Aug 16, 2016 at 10:55
2

I dont think their any way to detect charging speed: But you can do it problematically: 1) You can record charged level (percentage or number) by

int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); batteryTxt.setText(String.valueOf(level) + "%");

2) And then after some processing time you can again get the current charged level by using same code. 3) Then calculate the difference and and then you will be able to know the charging speed.

This is just the idea that how you can implement it.

Hope this will help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.