Get the remaining battery time available from an Android phone

一笑奈何 提交于 2019-12-28 06:48:14

问题


Is it possible to get the remaining battery time available from an Android phone?

Thanks.


回答1:


You can get battery life with help of broadcast receiver by registering a receiver for action Intent.ACTION_BATTERY_CHANGED. My answer is key only, get information from Android Developers website.

By using the below statement in onReceive() method of BroadcastReceiver with above Intent action, you will get battery level currently available(e.g., 50%, 60%, etc.). But you can't estimate the time remaining, because some apps may consume more power. So i think battery level to time remaining conversion won't give correct result.

battery_level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);

I hope it may help you.




回答2:


There are a few apps (battery widgets and the like) that estimate time remaining before the battery runs out. I'd guess they take current battery level and try to work out current drain based on processor usage, backlight level etc. In my experience they aren't too accurate but in principle if you get the algorithm right it should be possible.



来源:https://stackoverflow.com/questions/8923497/get-the-remaining-battery-time-available-from-an-android-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!