剩余时间电池放电在Android

剩余时间电池放电在Android

问题描述:

我要寻找一个code估计/猜测剩余时间前的android手机电池完全放电。我的搜索结果是完全的应用程序可用,也是共同的意见,这是pretty的无用来计算的话。但是我需要code。任何帮助,甚至是粗糙的片段,会做如何开始使用。

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 also the common comment that it's pretty much useless to calculate it. However i need the code. Any help, even a rough snippet, will do for getting started with.

您不能准确地猜到了多少时间剩余电池放电,因为可能有不同的应用程序或服务消耗电池。因此,它可能会有所不同。

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.

不过,你可以通过注册一个接收器,用于操作Intent.ACTION_BATTERY_CHANGED得到的电池寿命与广播接收器的帮助。我的答案是唯一的关键,获得Android开发者网站上的信息。

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.

通过使用下面的语句中的onReceive(BroadcastReceiver的的)方法与上述意图的动作,你会得到现有的电池电量(如50%,60%等)。但你不能估计剩余的时间,因为一些应用程序可能会消耗更多的功率。所以,我认为电池电量,以剩余时间转换将不会给出正确的结果。

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.