13

コードを使用してデバイスを再起動する方法があるかどうかを知りたいです。私はもう試した:

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

のアクセス許可を追加しましたREBOOTが、それでも機能しません。

ありがとう

4

6 に答える 6

35

これは私にとってはうまくいくようでした:

try {
        Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
        proc.waitFor();
    } catch (Exception ex) {
        Log.i(TAG, "Could not reboot", ex);
    }
于 2011-11-11T23:50:05.293 に答える
0

PowerManager を使用して再起動することもできます (これは再起動を保証するものではありません - OS がキャンセルする可能性があります): リンク
リンク #2

于 2015-03-07T16:39:17.313 に答える
0

私はザマリンを使用しています。私にとっての解決策は次のとおりです。

Java.Lang.Runtime.GetRuntime().Exec(new String[] { "/system/xbin/su", "-c", "reboot now" });
于 2017-09-27T14:57:17.387 に答える
0

Still for rooted devices, but in case you want safer (process.waitFor() is conditioned, in separate try-catch, we have proper exception handling, "now" added in command after reboot, which is necessary for some devices, etc.) and maybe cleaner code, take a look at this:

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:16:19.357 に答える
-1

これが解決策です。デバイスはルート化されている必要があることに注意してください。

try{
    Process p = Runtime.getRuntime().exec("su");
    OutputStream os = p.getOutputStream();                                       
    os.write("reboot\n\r".getBytes());
    os.flush();
}catch(IOException )
于 2012-10-26T22:59:47.593 に答える
-4

電話がルート化されている場合、実際には非常に簡単です。

try {
    Runtime.getRuntime().exec("su");
    Runtime.getRuntime().exec("reboot");
} catch (IOException e) {
}               

最初のコマンドは、スーパーユーザーの許可を求めます。2番目は、電話を再起動します。実際の再起動はアプリではなく、実行されたコマンドによって処理されるため、マニフェスト ファイルに追加のアクセス許可は必要ありません。

于 2011-01-23T07:43:30.727 に答える