Fórum Código, status de batéria #552563
27/04/2016
0
Fernando Ferreira
Curtir tópico
+ 0Posts
27/04/2016
Raylan Zibel
Gostei + 0
27/04/2016
Italo Junior
[url]http://stackoverflow.com/questions/3291655/get-battery-level-and-state-in-android[/url]
Gostei + 0
27/04/2016
Wolney Dias
public float getBatteryLevel() {
Intent batteryIntent = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
if(level == -1 || scale == -1) {
return 50.0f;
}
return ((float)level / (float)scale) * 100.0f;
}
Gostei + 1
30/04/2016
Fernando Ferreira
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)