How to shutdown an Android mobile programmatically?

前端 未结 6 1446
慢半拍i
慢半拍i 2020-11-28 13:12

Is it possible to shutdown the mobile programmatically. that is with out using su commands..

6条回答
  •  醉话见心
    2020-11-28 13:32

    If your device is rooted then you can try below solution

    Shutdown:

    try {
        Process proc = Runtime.getRuntime()
                        .exec(new String[]{ "su", "-c", "reboot -p" });
        proc.waitFor();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    

    Restart:

    Same code, just use "reboot" instead of "reboot -p".

提交回复
热议问题