开发者

Make button reboot phone (Rooted Phone)

Hi I am in need of some help I am working on an app where I want the to user click a button and the phone reboots. My proble开发者_开发知识库m is when I click the button it gives a super user request but does not reboot. My code is:

 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("su");
                 Runtime.getRuntime().exec("reboot");                
            } catch (IOException e) {
            }               
        }
    });

}

}

Is there anything I am doing wrong? If anyone could help i would really appreciate it.


You create two different shells this way. Assign the process to some variable and grab its IO streams:

Process p = Runtime.getRuntime().exec("su");
InputStream is = p.getInputStream();
// ...

Then write the command directly.

Note that this will not work on unrooted device. Avoid this if possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜