Runtime.exec() :在 Android 中重新启动?

2024-01-07

我正在寻找一种可用于重新启动已取得 root 权限的设备的解决方案。我知道重新启动设备对于用户来说是非常糟糕的设计,如这里所述 https://stackoverflow.com/questions/4030037/how-to-reboot-android-device,而且它并不是真正用于应用程序。主要目的是在测试期间重新启动手机(我正在开发视频聊天应用程序,有时当一切都不顺利时我需要重新启动)

我观察到,在终端中使用重新启动来重新启动手机要快得多(adb shell或 ConnectBot 为例),而不是像平常那样重新启动ACTION_REBOOT http://developer.android.com/reference/android/content/Intent.html#ACTION_REBOOT,无论如何我都无法使用。

目前,我可以获得超级用户权限,

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

但我无法进行实际的重新启动。我尝试了 G1(HTC)和 Galaxy S(三星),但没有成功。我找到了重新启动可执行文件/system/bin/reboot

以下是我的一些尝试:

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

I read 本文 http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html关于 Runtime.exec() 的陷阱,但我认为我不属于这种情况。

由于使用 ConnectBot 使我能够执行这样的操作,我非常确定这是可能的。请不要告诉我去看看连接机器人代码 https://github.com/kruton/connectbot/,这是一个大而复杂的项目:)

你能帮我解决这个问题吗?

Thanks.


最终经过几周的搜索:

Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot now"});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Runtime.exec() :在 Android 中重新启动? 的相关文章

随机推荐