pull/32/head
parent
1ca339c194
commit
ff95f864ef
@ -0,0 +1,16 @@ |
||||
package io.legado.app.utils |
||||
|
||||
import android.content.Context |
||||
import android.content.Intent |
||||
import android.content.IntentFilter |
||||
import android.os.BatteryManager |
||||
|
||||
object BatteryUtils { |
||||
|
||||
fun getLevel(context: Context): Int { |
||||
val iFilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED) |
||||
val batteryStatus = context.registerReceiver(null, iFilter) |
||||
|
||||
return batteryStatus?.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) ?: -1 |
||||
} |
||||
} |
Loading…
Reference in new issue