【问题标题】:Reboot Android Device running 4.0重新启动运行 4.0 的 Android 设备
【发布时间】:2012-09-17 14:48:50
【问题描述】:

我已在清单中设置权限:

<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

【问题讨论】:

    标签: android exception reboot


    【解决方案1】:

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

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

    【讨论】:

    • 您有什么建议可以将自定义模组安装到模拟器上,以便我的应用具有与操作系统相同的签名证书?
    【解决方案2】:

    如果有人还在寻找,而我们确实在谈论有根设备,请阅读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.
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-01-01
      • 1970-01-01
      • 2019-05-19
      • 2017-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多