feat: 组件解耦
This commit is contained in:
@@ -57,7 +57,7 @@ class DeviceServiceManager(val context: Application) : ConnectivityManager.Netwo
|
||||
/**
|
||||
* 系统电量
|
||||
*/
|
||||
private val _batteryPercentage = MutableStateFlow(-1)
|
||||
private val _batteryPercentage = MutableStateFlow(getBatteryLevel(context))
|
||||
val batteryPercentage = _batteryPercentage.asStateFlow()
|
||||
|
||||
/**
|
||||
@@ -293,6 +293,11 @@ class DeviceServiceManager(val context: Application) : ConnectivityManager.Netwo
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBatteryLevel(context: Context): Int {
|
||||
val bm = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
|
||||
return bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||
}
|
||||
|
||||
inner class SysKeyReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
val action = intent?.action ?: return
|
||||
|
||||
Reference in New Issue
Block a user