Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
738 views
in Technique[技术] by (71.8m points)

java - Runtime.exec() : Reboot in Android?

I'm looking for a solution which can be used to reboot a rooted device. I jknow that rebooting a device is very poor design for the user, as stated here, and it's not really for an application. The main purpose is to reboot the phone during my tests (I work on a video chat application, and sometimes I need to reboot when everything goes south)

I observed that rebooting a phone is far far quicker using reboot in a terminal (adb shell or ConnectBot for instance) than going through the usual of rebooting with the ACTION_REBOOT, that I can't use anyway.

For the moment, I'm able to get the superuser privileges, with

Process root = Runtime.getRuntime().exec("su");

But I can't do the actual reboot. I try on a G1 (HTC) and on a Galaxy S (Samsung) without any success. I located the reboot executable in /system/bin/reboot

Here are some of my attempts :

Process reboot = Runtime.getRuntime().exec("/system/bin/reboot");
Process reboot = Runtime.getRuntime().exec("reboot");
Process reboot = Runtime.getRuntime().exec("su reboot"); 

I read this article about the pitfalls of Runtime.exec(), but I think I'm not in this case.

As using ConnectBot enable me to do such an action, I'm pretty sure it's possible. Please don't tell me to go and have a look to the ConnectBot code, it's a big and complicated project :)

Can you help me with this issue ?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Finally after weeks of searching:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...