コードを使用してデバイスを再起動する方法があるかどうかを知りたいです。私はもう試した:
Intent i = new Intent(Intent.ACTION_REBOOT);
i.putExtra("nowait", 1);
i.putExtra("interval", 1);
i.putExtra("window", 0);
sendBroadcast(i);
のアクセス許可を追加しましたREBOOT
が、それでも機能しません。
ありがとう
これは私にとってはうまくいくようでした:
try {
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
proc.waitFor();
} catch (Exception ex) {
Log.i(TAG, "Could not reboot", ex);
}
私はザマリンを使用しています。私にとっての解決策は次のとおりです。
Java.Lang.Runtime.GetRuntime().Exec(new String[] { "/system/xbin/su", "-c", "reboot now" });
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.
}
}
これが解決策です。デバイスはルート化されている必要があることに注意してください。
try{
Process p = Runtime.getRuntime().exec("su");
OutputStream os = p.getOutputStream();
os.write("reboot\n\r".getBytes());
os.flush();
}catch(IOException )
電話がルート化されている場合、実際には非常に簡単です。
try {
Runtime.getRuntime().exec("su");
Runtime.getRuntime().exec("reboot");
} catch (IOException e) {
}
最初のコマンドは、スーパーユーザーの許可を求めます。2番目は、電話を再起動します。実際の再起動はアプリではなく、実行されたコマンドによって処理されるため、マニフェスト ファイルに追加のアクセス許可は必要ありません。