2012-09-17 37 views
0

我已设置权限:重新启动Android设备清单中的运行4.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 

回答

2

REBOOT权限只授予具有平台签名或作为系统应用程序。

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

+0

你有什么建议获得自定义MOD到一个仿真器,因此我的应用程序具有相同签名证书的操作系统吗? –

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. 
    } 
} 
相关问题