Reputation: 743
I am developing android application for android tablets and I try do that when device is charging connect turn on to device.Is it possible to automatically power on the android device when charging is connected?
Upvotes: 0
Views: 1334
Reputation: 208
It depends which device is it. You basically need to update the battery loading animation file with a shell script to restart the device, but you have to know which file is responsible for animating your battery icon. Each OEM has its own standard of naming/locating the animation file and you should find yours.
Upvotes: 1
Reputation: 73
First of all you have to register broadcast receiver for `ACTION_BATTERY_CHANGED ':
BroadcastReceiver PowerStatusReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Intent batteryStatus = context.getApplicationContext().registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
assert batteryStatus != null;
status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
and you will have 2 options:
if (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL) {
// device plugged
// ...
}else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
// device unplugged
// ...
}
and:
IntentFilter powerConnectedFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(PowerStatusReceiver, powerConnectedFilter);
And to keep the screen on while the device is plugged, see: Android Keep Screen On In App
Good luck :)
Upvotes: 0