charging-fix
This commit is contained in:
parent
2f421923a6
commit
7098c8f450
1 changed files with 7 additions and 1 deletions
|
@ -643,13 +643,19 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
||||||
|
|
||||||
val battery: BatteryManager =
|
val battery: BatteryManager =
|
||||||
requireContext().getSystemService(Context.BATTERY_SERVICE) as BatteryManager
|
requireContext().getSystemService(Context.BATTERY_SERVICE) as BatteryManager
|
||||||
|
val batteryIntent = requireContext().registerReceiver(null,
|
||||||
|
IntentFilter(Intent.ACTION_BATTERY_CHANGED))
|
||||||
|
|
||||||
val capacity = battery.getIntProperty(BATTERY_PROPERTY_CAPACITY)
|
val capacity = battery.getIntProperty(BATTERY_PROPERTY_CAPACITY)
|
||||||
val nowUAmps = battery.getIntProperty(BATTERY_PROPERTY_CURRENT_NOW)
|
val nowUAmps = battery.getIntProperty(BATTERY_PROPERTY_CURRENT_NOW)
|
||||||
|
|
||||||
sb.append(String.format("%.1fA (%d%%)", nowUAmps / 1000000.0, capacity))
|
sb.append(String.format("%.1fA (%d%%)", nowUAmps / 1000000.0, capacity))
|
||||||
|
|
||||||
if (battery.isCharging || nowUAmps > 0.0) {
|
val status = batteryIntent?.getIntExtra(BatteryManager.EXTRA_STATUS, -1)
|
||||||
|
val isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
|
||||||
|
status == BatteryManager.BATTERY_STATUS_FULL
|
||||||
|
|
||||||
|
if (isCharging) {
|
||||||
sb.append(" ${getString(R.string.charging)}")
|
sb.append(" ${getString(R.string.charging)}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue