I want to measure the value of current(mA) during the charging of Android phone. How can I read the current and display it in my application?
您可以使用BatteryManager类和BATTERY_PROPERTY_CURRENT_NOW
属性读取电池上的电流。
val mBatteryManager = this.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
val current = mBatteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW).div(1000)
Keep in mind that this might not work on some devices like samsung, realme, huawei.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.