Search code examples
androidboot

Boot android, if there is power


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?


Solution

  • 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();
    }