-6

There is such a task - to include an android device, if there is power and turn off programmatically. I know that in order to turn off, you need a root (it will). But is there any way to turn on the device if the power is applied?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Sergey Grishin
  • 392
  • 2
  • 16
  • It's entirely dependent on the hardware, not software. If the main board has a jumper that powers on the device when an input voltage is detected, then it will do so. This is mainly for Android devices that do not have a battery, mind. If not, you'd need to hold the power button as usual. – Michael Dodd Feb 14 '18 at 10:36
  • For turn off the device you can visit the following link https://stackoverflow.com/questions/3745523/programmatically-switching-off-android-phone – Arya Feb 14 '18 at 10:37
  • Thanks for suggestion adout turn off, I will it. About boot: in my case I can set timer in android settings, so device will turn on at 5:00AM (for example). For me it fits – Sergey Grishin Feb 14 '18 at 11:19

1 Answers1

0

So, in my case I can use system scheduler for boot device at specialised time (f.e. 5:00 AM) and with root access shutdown device with this code

try {
    Runtime.getRuntime()
           .exec(new String[] { "su", "-c", "reboot -p" })
           .waitFor();
} catch (Exception ex) {
    ex.printStackTrace();
}
Sergey Grishin
  • 392
  • 2
  • 16