本文介绍了如何以编程方式重启手机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建应用程序(仅适用于Android 6),在该应用程序中,我必须使用按钮单击才能提供重新启动功能.我正在使用以下代码:

I am creating app(only for Android 6) in which I have to give reboot functionality using button click.I am using following code:

PowerManager pm =(PowerManager) getSystemService(Context.POWER_SERVICE);
pm.reboot(null);

并添加了权限:

uses-permission android:name="android.permission.REBOOT",
uses-permission android:name="android.permission.DEVICE_POWER" ,
uses-permission android:name="android.permission.MODIFY_PHONE_STATE"

但出现以下错误:

推荐答案

请尝试

try {
Runtime.getRuntime().exec("su");
  Runtime.getRuntime().exec("reboot");
} catch (IOException e) {
}

OR

Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot now"});

如果不起作用: Runtime.getRuntime().exec(new String [] {"su",-c",立即重启"}); 代替

您可能会使用PowerManager使其重新启动(这不能保证它将重新启动-操作系统可能会取消它):

You could possibly use the PowerManager to make it reboot (this does not guarantee that it'll reboot - OS may cancel it):

http://developer.android.com/reference/android/os/PowerManager.html#reboot(java.lang.String)

重新启动设备.如果重新启动成功,将不会返回.需要REBOOT权限.

Reboot the device. Will not return if the reboot is successful.Requires the REBOOT permission.

http://developer.android.com/reference/android/Manifest.permission.html#REBOOT

必须能够重新启动设备.不适用于第三方应用程序.常量值:"android.permission.REBOOT"

Required to be able to reboot the device. Not for use by third-party applications. Constant Value: "android.permission.REBOOT"

您需要使用系统固件密钥对您的应用进行签名.但是您的应用程序可能具有 Root 特权.尝试使用以下代码(如果您具有SU访问权限)

You need to sign your app with the System Firmware Key. But it's possible for your app with Root privileges. Try using the following code (if you have SU access):

关闭:

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

重启:

相同的代码,只需使用"reboot" 而不是"reboot -p" .

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

这些不能在Stock HTC ROM上运行,但尚未确认自己身份

这篇关于如何以编程方式重启手机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:07