I want to display Battery level stats in my app. How can we obtain such information like Battery Power, Battery Voltage, etc.?
So, how to check screen time on Android? From your device's home screen, pull down the Quick Settings panel, and tap on the battery icon that you'll see in the upper right corner. Once you do that, a Battery menu will show up, displaying detailed info on what's draining your battery.
Go to Settings > Battery (the app's location may vary for your version of Android) and you'll see a history graph detailing which apps have been consuming the most battery power and how long you can use the device before the battery is completely drained off.
Settings > Battery > Usage details Open Settings and tap on the Battery option. Next select Battery Usage and you'll be given a breakdown of all the apps that are draining your power, with the most-hungry ones at the top. Some phones will tell you how long each app has been actively used – others won't.
BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
context.unregisterReceiver(this);
int rawlevel = intent.getIntExtra("level", -1);
int scale = intent.getIntExtra("scale", -1);
int level = -1;
if (rawlevel >= 0 && scale > 0) {
level = (rawlevel * 100) / scale; /* This is your battery level */
}
}
};
IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(batteryLevelReceiver, batteryLevelFilter);
}
or check out this guy (who wrote the code I posted): http://mihaifonoage.blogspot.com/2010/02/getting-battery-level-in-android-using.html
Is this of any help?
public class Main extends Activity {
private TextView contentTxt;
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent intent) {
// TODO Auto-generated method stub
int level = intent.getIntExtra("level", 0);
contentTxt.setText(String.valueOf(level) + "%");
}
};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
contentTxt = (TextView) this.findViewById(R.id.monospaceTxt);
this.registerReceiver(this.mBatInfoReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
}
Also, see this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With