How to test battery charging speed?

10,297

Solution 1

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

Solution 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

Share:
10,297

Related videos on Youtube

Kishan Vaghela
Author by

Kishan Vaghela

Updated on June 04, 2022

Comments

  • Kishan Vaghela
    Kishan Vaghela almost 2 years

    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.

  • Kishan Vaghela
    Kishan Vaghela over 7 years
    It is added in API 21. Can you provide the solution that also work in lower version.?
  • Jehy
    Jehy over 7 years
    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.