Log battery level

This commit is contained in:
M66B
2020-11-04 15:15:08 +01:00
parent 6f60234833
commit b89a3e9935
2 changed files with 12 additions and 1 deletions

View File

@@ -424,6 +424,16 @@ public class Helper {
return null;
}
static Integer getBatteryLevel(Context context) {
try {
BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
return bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
} catch (Throwable ex) {
Log.e(ex);
return null;
}
}
static boolean isCharging(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return false;