Frage

Is there a way of accurately determining the amount of battery life remaining on the battery in hours/minutes?

I know I can register an Intent receiver to receive the broadcast for ACTION_BATTERY_CHANGED and get the level and scale and use those to get the percentage like so:

int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);

float batteryPct = level / (float)scale;

My guess is that it is going to require a lot of different variables (type of battery, processor, number of apps running, display brightness, etc) but I just want to be sure I haven't overlooked anything.

Does anyone have any idea if it is possible to get this detail or suggestions on where/how to start?

War es hilfreich?

Lösung

Personally, I think that considering the type of battery, processor and number of apps running is overkill. All physical hardware is going to have different performance (especially batteries) regardless of brand. Also, different connectivity and processes will consume more or less battery based on its quality.

It's impossible to know for certain what kind of applications the user will start up and for how long they'll be running (ie. your user might watch 10 minutes of youtube over wifi, or attempt to watch 90 minutes on a varying signal strength data connection).

If I was doing it, I'd measure burn rates on your battery life every few minutes and use some polynomial maths to estimate a trend.

Wikipedia isn't the best place to learn your maths, but if want some information about how trend lines work, start here: http://en.wikipedia.org/wiki/Linear_regression#Trend_line

That's just my ideas on your situation... Hope it helps.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top