开发者

How to power off an Android device?

开发者 https://www.devze.com 2022-12-16 12:03 出处:网络
How could I power off an android device via java code? Is it even possible? Do I need special permis开发者_开发问答sions to do this?There is no API in the Android SDK to allow user apps to do this.

How could I power off an android device via java code?

Is it even possible? Do I need special permis开发者_开发问答sions to do this?


There is no API in the Android SDK to allow user apps to do this.

The closest you could perhaps try would be PowerManager.goToSleep().


Yes, It is possible but you need a Rooted device with Superuser Access. Try using the following code:

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

If you plan on doing this without Root Privileges, forget it. The only way to do that is to use PowerManager but that won't work unless your app is signed with the System Firmware Key.

[via Programmatically switching off Android phone]

0

精彩评论

暂无评论...
验证码 换一张
取 消