-1

I need to get the current charge percentage in decimal values like -> 50.3,20.4,etc...

Is there any way to do the same in android with Kotlin/Java.

Anyone Please help me with this.

Algorithm / Code to get the Current battery Percentage in Decimals. like 15.2 like this.

Krithick
  • 1
  • 1

1 Answers1

0
BatteryManager bm = (BatteryManager)getSystemService(BATTERY_SERVICE);
int batteryLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
float batteryPercent = batteryLevel / 100f;
Dupe Tv
  • 9
  • 1
  • Still no change bro I am getting the charge % as 0.57 if the charge is 57 But I neet it like 57.3,57.4 and so on – Krithick Mar 07 '23 at 06:34
  • This is clearly wrong. `BATTERY_PROPERTY_CAPACITY` is documented as "Remaining battery capacity as an integer percentage of total capacity (with no fractional part)." – Ryan M Mar 07 '23 at 09:58