How to check battery capacity Android Wear (API level 20)

2.2k views Asked by At

I would like to readout the battery capacity left from my Moto 360. I've come along watch faces that show this value, but I was wondering how to get it. I would like to display this value on my own watch face i'm creating.

From API level 21 it is possible to use BatteryManager.BATTERY_PROPERTY_CAPACITY, but is there another command that I can use for API level 20?

Thanks

1

There are 1 answers

0
ianhanniballake On BEST ANSWER

Per the battery monitoring training, you can get the current battery information by using:

IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, ifilter);
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
float batteryPct = level / (float)scale;

Note that you need to continue to call this repeatedly to get the updated battery level. As waking up your app and checking this does take battery itself, they suggest:

Typically you should maximize the rate of your background updates in the case where the device is connected to an AC charger, reduce the rate if the charge is over USB, and lower it further if the battery is discharging.