Android Question Programmically reboot android device

JohnC

Expert
Licensed User
Longtime User
I need to be able to programmically reboot an android device.

I found two solutions at stack overflow:

http://stackoverflow.com/questions/4966486/reboot-the-phone-on-a-button-click

But the above solution requires a "system" signing key.

Another solution looks doable, but I don't know how to convert to VB:

http://stackoverflow.com/questions/4580254/android-2-2-reboot-device-programmatically

B4X:
try {
        Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
        proc.waitFor();
    } catch (Exception ex) {
        Log.i(TAG, "Could not reboot", ex);
    }

Anyone know how to convert the above for use in B4A?
 

JohnC

Expert
Licensed User
Longtime User
Understood - the devices my app is designed for are all rooted (RikoMagic MK802IV, ect).
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
That example looks like it could be related (if ".Shell" = ".exec")

But it still requires a decent amount of syntax conversion to go from A to B that I don't know how to do.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Give this code a shot:
B4X:
Private p As Phone
Private Out, Err As StringBuilder
			
Out.Initialize
Err.Initialize
   
File.WriteString(File.DirRootExternal, "reboot.sh", "su -c reboot")

p.Shell("sh", Array As String(File.Combine(File.DirRootExternal, "reboot.sh")), Out, Err)
 
Upvote 1

JohnC

Expert
Licensed User
Longtime User
That worked! Sweet.

It would have taken me hours with trial and error to figure out that syntax.

Thanks!
 
Upvote 0
Top