Is it possible to calculate remaining battery time in hours and minutes? Also, would it be able to calculate this time depending on if I'm using a certain app? Is it even possible to get such information? If you could please give me advice on how to do that, I'd be very thankful.
是否可以以小时和分钟计算剩余电池时间?此外,它是否能够计算这个时间取决于我是否使用某个应用程序?是否有可能获得此类信息?如果你能告诉我如何做到这一点的建议,我会非常感激。
3 个解决方案
#1
Estimating the remaining battery life is based on analytics. As the other people said you have to listen for battery level changes and in addition you have to keep track of them. After some time you will have enough data to calculate what is the average time the battery lasts. In addition you know when the battery drains fast and when drains slow so you can improve your estimation based on this. Also you will know in what time the user charges the devices. There are a lot of events that can be tracked and using the battery level. In addition you can also track when the screen is on or off. The algorithm of calculating the remaining battery life depends on you :)
估算剩余电池寿命取决于分析。正如其他人所说,你必须听取电池电量变化,此外你必须跟踪它们。一段时间后,您将有足够的数据来计算电池持续的平均时间。此外,您知道电池何时快速耗尽以及何时排水速度较慢,因此您可以根据此情况改善估计。您还将知道用户在何时收取设备费用。有很多事件可以跟踪并使用电池电量。此外,您还可以跟踪屏幕打开或关闭的时间。计算剩余电池寿命的算法取决于你:)
I hope this explains (at least a bit) the idea of the estimation the battery life.
我希望这能解释(至少有点)估计电池寿命的想法。
#2
I don't know the code, but I can help you the logic/formula for this question:
我不知道代码,但我可以帮助你解决这个问题的逻辑/公式:
- Collect all information from the battery statistics, and count the usage in total. Then calculate the usage per second, how much the battery was drained per second.
- Get the battery capacity in mAh, and calculate the remaining live with this formula:
total capacity per speed of the usage
.
从电池统计信息中收集所有信息,并统计使用情况。然后计算每秒的使用量,每秒耗尽的电量。
以mAh为单位获取电池容量,并使用以下公式计算剩余电量:每次使用速度的总容量。
Oddly enough, for some battery app developers know the code, such as DU Battery Saver.
奇怪的是,对于一些电池应用开发者来说,知道代码,例如DU Battery Saver。
#3
You can use BatteryManager library to checkout the battery status with EXTRA_LEVEL:
您可以使用BatteryManager库通过EXTRA_LEVEL检查电池状态:
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);
Unfortunately, you can get the remaining time only with approximation because some apps may consume more power.
不幸的是,您只能通过近似获得剩余时间,因为某些应用可能会消耗更多功率。
Cheers
#1
Estimating the remaining battery life is based on analytics. As the other people said you have to listen for battery level changes and in addition you have to keep track of them. After some time you will have enough data to calculate what is the average time the battery lasts. In addition you know when the battery drains fast and when drains slow so you can improve your estimation based on this. Also you will know in what time the user charges the devices. There are a lot of events that can be tracked and using the battery level. In addition you can also track when the screen is on or off. The algorithm of calculating the remaining battery life depends on you :)
估算剩余电池寿命取决于分析。正如其他人所说,你必须听取电池电量变化,此外你必须跟踪它们。一段时间后,您将有足够的数据来计算电池持续的平均时间。此外,您知道电池何时快速耗尽以及何时排水速度较慢,因此您可以根据此情况改善估计。您还将知道用户在何时收取设备费用。有很多事件可以跟踪并使用电池电量。此外,您还可以跟踪屏幕打开或关闭的时间。计算剩余电池寿命的算法取决于你:)
I hope this explains (at least a bit) the idea of the estimation the battery life.
我希望这能解释(至少有点)估计电池寿命的想法。
#2
I don't know the code, but I can help you the logic/formula for this question:
我不知道代码,但我可以帮助你解决这个问题的逻辑/公式:
- Collect all information from the battery statistics, and count the usage in total. Then calculate the usage per second, how much the battery was drained per second.
- Get the battery capacity in mAh, and calculate the remaining live with this formula:
total capacity per speed of the usage
.
从电池统计信息中收集所有信息,并统计使用情况。然后计算每秒的使用量,每秒耗尽的电量。
以mAh为单位获取电池容量,并使用以下公式计算剩余电量:每次使用速度的总容量。
Oddly enough, for some battery app developers know the code, such as DU Battery Saver.
奇怪的是,对于一些电池应用开发者来说,知道代码,例如DU Battery Saver。
#3
You can use BatteryManager library to checkout the battery status with EXTRA_LEVEL:
您可以使用BatteryManager库通过EXTRA_LEVEL检查电池状态:
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL,0);
Unfortunately, you can get the remaining time only with approximation because some apps may consume more power.
不幸的是,您只能通过近似获得剩余时间,因为某些应用可能会消耗更多功率。
Cheers