0

I am trying to shutdown my custom android device programatically. I am using the below code to do the same, but it is restarting again.I want the device to be completely shut down.

Intent intent = new Intent("android.intent.action.ACTION_REQUEST_SHUTDOWN");
            intent.putExtra("android.intent.extra.KEY_CONFIRM", false);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);

How to achieve complete shut down i,e avoid auto restart?

Note: I have signed app with platform signatures. Placed it in /system/app Added <uses-permission android:name="android.permission.SHUTDOWN" /> permission in manifest.

user2879697
  • 69
  • 1
  • 10

3 Answers3

1

If your device is rooted, you can use this code for shutdown

Java.Lang.Runtime.GetRuntime().Exec(new String[] { "/system/xbin/su", "-c", "reboot -p" });

and use this code for Reboot

Java.Lang.Runtime.GetRuntime().Exec(new String[] { "/system/xbin/su", "-c", "reboot now" });

I use this on Xamarin.Android

0

Try this code, it might help.

try {
    Process p = Runtime.getRuntime().exec(new String[]{ "su", "-c", "reboot" });
 p.waitFor();
} catch (Exception ex) {
    ex.printStackTrace();
}
Mande Kira
  • 190
  • 1
  • 14
0
Intent i = new Intent("android.intent.action.ACTION_REQUEST_SHUTDOWN");
i.putExtra("android.intent.extra.KEY_CONFIRM", true);
startActivity(i);
Manish Singh Rana
  • 822
  • 1
  • 13
  • 26