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?
Asked
Active
Viewed 1,088 times
2 Answers
1
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.

Levon Shirakyan
- 188
- 2
- 11
0
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 :)

Community
- 1
- 1

Mihai Coman
- 73
- 1
- 9
-
Thank you for your answers but I want to do that when the device plugged if device turn off,device will be turn on.your answer for the a applicaiton – Diego Apr 07 '16 at 11:35
-
Ok. Now I got it... I think you can do this only hardware, because if the device is turned off, then the Android OS is not running, and for sure, any app can not handle this. :) Could be 2 solutions: rewrite the bootloader of the device (with a custom one), or a electronic circuit tied between the USB plug and the power button. None of the options is not universal :( – Mihai Coman Apr 07 '16 at 11:45