Can't reboot device using runtime.exec

隐身守侯 提交于 2019-12-06 12:23:05

Depending on how you've obtained root permission on your device, you can do any of the following:

Runtime.getRuntime().exec(new String[]{"/system/xbin/su","-c","reboot"});

or

Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot"});

or

Runtime.getRuntime().exec(new String[]{"su","-c","reboot"});

Probably better to test all three scenarios in your application.

Finally after weeks of searching:

Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot now"});

Try running "su /system/bin/reboot" instead of su and the command on different lines. That might help :)

If you want a button to be pressed try:

final Button button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
             try {
                 Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot"});              
            } catch (IOException e) {
            }               
        }
    });

By the way for this code to work the button has to be called button1.

Andro X

instead of {"/system/bin/su","-c","reboot"} i changed the "/system/bin/su" part to just "su" and then it worked for me.

Like this Runtime.getRuntime().exec(new String[]{"su","-c","reboot"});

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!