0

I want reboot the device. i am able to do with root.using below code.

  public static void rebootDevice()
    {
        try
        {
            Process process = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(process.getOutputStream());
            os.writeBytes("reboot \n");
        }
        catch (Throwable t) {

            t.printStackTrace();
            }
    }

but boss told me try without using su . how to do that any help?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Gaju Kollur
  • 2,046
  • 5
  • 23
  • 47
  • There are API's for this, but they only work in special cases. https://developer.android.com/reference/android/os/PowerManager#reboot(java.lang.String) – Afshin May 10 '18 at 06:27

1 Answers1

2

Unfortunately its not possible if you neither have root permission nor your app is system app. If your app is a System app then you can do following:

In your Manifest file put following permission:

<uses-permission android:name="android.permission.REBOOT"/>

Use following code to restart:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
pm.reboot(null);
Sagar
  • 23,903
  • 4
  • 62
  • 62