-1

I am trying shut down and reboot in my app. I googled and found some answered questions on stackoverflow but all says device must be rooted that is not possible in my case. also these commands are device specific. Is there any option to shut down or reboot android device programaticaly
tried following things

String command="/system/bin/reboot";

        try { // Run Script

            proc = runtime.exec("su");
            osw = new OutputStreamWriter(proc.getOutputStream());
                                osw.write(command);
                    osw.flush();
            osw.close();

        } catch (IOException ex) {}

and

Runtime.getRuntime().exec(new String[]{"su","-c","reboot now"});
Mahesh
  • 1,257
  • 1
  • 14
  • 24
  • you might be able to do it without root on your device if you are able to sign your application with device keys . – liorlis Aug 30 '15 at 11:23

1 Answers1

0

The devices i've got now are rooted so i can't test it but any how you need to sign your application with device keys or make it a system app.

This is an example for app that works fine for me :

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);
   PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
   pm.reboot(null);
}

And add to manifest :

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

Hope it helps

liorlis
  • 216
  • 3
  • 14