安卓2.2:重新启动设备编程重新启动、设备

2023-09-12 03:35:56 作者:Yrainy

我想知道是否有一种方法来重新启动设备通过code。香港专业教育学院的尝试:

I would like to know if there is a way to reboot the device through code. Ive tried:

Intent i = new Intent(Intent.ACTION_REBOOT); 
i.putExtra("nowait", 1); 
i.putExtra("interval", 1); 
i.putExtra("window", 0); 
sendBroadcast(i);

和添加权限重启,但它仍然不工作。

And added permissions for REBOOT but it still doesnt work.

感谢

推荐答案

这似乎为我工作:

try {
        Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
        proc.waitFor();
    } catch (Exception ex) {
        Log.i(TAG, "Could not reboot", ex);
    }