Can i get how much time i have before the battery goes to 0%? Something using a CountDownTimer
and making a stime of how much mAh the battery consume? Someone can help me to do it?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Short answer: No.
Long answer: Yes, you can.. But not that easily.. Because you don't know how much energy does the device consume at a time basis, you should first try to find that out and then calculate the remaining time using that data...
As you might have guessed already, it might not be that accurate at first but the more you
sample
, the more accurate that data will be.. So to conclude here is what you have to do:First when the user opens the app, because you don't have enough data about energy consumption, You should just display something like
Calculating...
. Here you should decide to have a sample time. That is something likederivation
in math..Let's say you have a sample time of 10 seconds. ( Your actual one should be bigger I guess. )
You should have a variable named something like
level1
.. Save the current level to it. Wait for the amount ofsample time
which is now 10 seconds.. Now save the current value tolevel2
.. Save thelevel1 - level2
product to another variable likeconsumed
.Now here is the magic. You know how much power has been consumed in 10 seconds (That is the
consumed
variable).. From now on you can calculate the remaining time using that data. But remember it's still one 10 second. What if that 10 seconds user was playing a heavy game or even the device was on stand by? That is why it's not accurate. But until now..What you can do is to add the
consumed
variable to an array named likesample_data
. Let the process go on and sample the consumption every 10 seconds and add it to the array. The more data you get, the more accurate your calculation will be.Then you can easily calculate the time remaining using the average of samples in the array.. Easy Peasy :p
You can not accurately guess that how much time is remaining for battery discharge, you can just make some estimation.
You can get battery life with help of broadcast receiver by registering a receiver for action
Intent.ACTION_BATTERY_CHANGED
Edit:
What you should do, is periodically get the
battery_level
and check how much battery is being consumed per minute / per hour, and make some calculations.So if your battery is 80% an decreasing 4% per hour, you have 20 hours estimated battery life