得到我有多少时间电池变为0%之前的Andr​​oid [英] get how much time i have before the battery goes to 0% Android

查看:216
本文介绍了得到我有多少时间电池变为0%之前的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以得到我有多少时间电池变为0%之前?用东西 CountDownTimer ,使电池多少毫安时消耗STIME?有人可以帮我做吗?

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?

推荐答案

简短的回答:没有。

龙答:是的,可以。但不是很容易。因为你不知道多少能源设备是否在同一时间的基础消耗,你应该首先尝试寻找出来,然后计算剩余时间使用该数据...

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 like derivation in math..

让我们说你有10秒的采样时间。 (您的实际应该更大,我猜。)

Let's say you have a sample time of 10 seconds. ( Your actual one should be bigger I guess. )

您应该有一个变量的东西像名为(第一级) ..目前的水平保存它。等待采样时间这是现在10秒..当前值现在保存到级别2 ..保存量在 1级 - 2级产品另一个变量如消耗

You should have a variable named something like level1.. Save the current level to it. Wait for the amount of sample time which is now 10 seconds.. Now save the current value to level2.. Save the level1 - level2 product to another variable like consumed.

现在这里是神奇的。你知道多少力量已经在10秒(这是消耗变量)..被消耗从现在开始,你可以使用这些数据计算出的剩余时间。但是,请记住它仍然是1个10秒。如果有10秒用户在玩游戏的沉重,甚至设备是在待机?这就是为什么它是不准确的。但是到现在为止..

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

你可以做的是将消耗变量添加到名为像 SAMPLE_DATA 的数组。让该过程继续并品尝消费每10秒,并将其添加到阵列。你获得的数据越多,越精确你的计算会。

What you can do is to add the consumed variable to an array named like sample_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.

然后你就可以很容易地计算出使用样本的平均值阵列中的剩余时间..易peasy:P

Then you can easily calculate the time remaining using the average of samples in the array.. Easy Peasy :p

这篇关于得到我有多少时间电池变为0%之前的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆