0

我在清单中设置了权限:

<uses-permission android:name="android.permission.REBOOT" />

我调用以下几行来重新启动设备:

Intent intent = new Intent(Intent.ACTION_REBOOT);
sendBroadcast(intent);

由于我在模拟器中有root权限,我很好奇为什么会遇到以下错误:

 Permission Denial: not allowed to send broadcast android.intent.action.REBOOT from pid=963, uid=10046
4

2 回答 2

2

REBOOT 权限仅授予具有平台签名或系统应用程序的应用程序。

作为 root 可能允许您以 root 身份运行命令,但您的应用程序仍然不是。(不过,您可以 sudo 调用关闭命令)

于 2012-09-17T14:51:49.113 回答
0

如果有人仍在寻找并且我们确实在谈论有根设备,请阅读此答案

以下代码示例应该这样做(根据请求添加):

Process rebootProcess = null;
try
{
    rebootProcess = Runtime.getRuntime().exec("su -c reboot now");
}
catch (IOException e)
{
    // Handle I/O exception.
}

// We waitFor only if we've got the process.
if (rebootProcess != null)
{
    try
    {
        rebootProcess.waitFor();
    }
    catch (InterruptedException e)
    {
        // Now handle this exception.
    }
}
于 2014-09-18T17:23:14.183 回答