My app uses BatteryManager.BATTERY_PROPERTY_CURRENT_NOW to get the battery current of the device:
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
int current = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW), context);
However, it does not work for example on a Samsung Galaxy Tab A. There it returns just 0.
Other apps show the current even on that device. How do they do it? What are alternatives to my method?
From your question ("returns just 0") please take a look at the documentation on getIntProperty: https://developer.android.com/reference/android/os/BatteryManager#getIntProperty(int)
If the property is not supported or there is any other error, return
(a) 0 if targetSdkVersion < VERSION_CODES.P
or
(b) Integer.MIN_VALUE if targetSdkVersion >= VERSION_CODES.P.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With