Remaining time to battery discharge on android

后端 未结 3 508
遇见更好的自我
遇见更好的自我 2021-01-14 21:42

I am looking for a code for estimating/guessing time remaining before the android phone battery is completely discharged. My search results were full of apps available and a

3条回答
  •  时光说笑
    2021-01-14 22:21

    You can not accurately guess that how much time is remaining for battery discharge, because there might be different applications or service consuming battery. thus it might vary.

    However 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.

提交回复
热议问题