我在清单中设置了权限:
<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
答案 0 :(得分:2)
REBOOT权限仅授予具有平台签名或系统应用程序的应用程序。
成为root可能允许您以root身份运行命令,但您的应用仍然不是。 (你可以sudo调用shutdown命令)
答案 1 :(得分:0)
如果有人还在寻找并且我们确实在谈论有根设备,请阅读this answer。
以下代码示例应该这样做(根据请求添加):
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.
}
}