Android 尝试以编程方式重新启动根安卓设备
我正在尝试以编程方式重新启动Galaxy S3 我尝试过的事情:Android 尝试以编程方式重新启动根安卓设备,android,root,Android,Root,我正在尝试以编程方式重新启动Galaxy S3 我尝试过的事情: try { Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" }); proc.waitFor(); } catch (Exception ex) { Log.i("RebootActivity", "Could not reboot", ex); }
try {
Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
proc.waitFor();
} catch (Exception ex) {
Log.i("RebootActivity", "Could not reboot", ex);
}
try {
Runtime.getRuntime().exec(new String[]{"su","-c","reboot now"});
} catch (IOException e) {
e.printStackTrace();
}
try
{
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("reboot now\n");
}
catch (Throwable t)
{
t.printStackTrace();
}
你们知道怎么做吗
谢谢。试着用一个像“su\n reboot;\n”这样的普通字符串来代替数组。 尝试从shell获取答案,这对调试有很大帮助 您的su二进制文件的权限是什么?如果它们是错误的,您可以在“mount-oremount,rw/system”之后尝试使用“chmod 7777/system/xbin/su” 下面是一些示例代码:运行string命令,它是一个\n and or;linux shell命令的单独列表
StringBuffer commandOutput = new StringBuffer();
try {
Process process = Runtime.getRuntime().exec("su\n");
DataOutputStream out = new DataOutputStream(process.getOutputStream());
out.writeBytes("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/vendor/lib:/system/lib\n");
out.writeBytes(command+"\n");
out.flush();
process.waitFor();
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
int numRead;
char[] buffer = new char[1000];
while ((numRead = in.read(buffer)) > 0) {
commandOutput.append(buffer, 0, numRead);
}
in.close();
process.waitFor();
} catch ...
return commandOutput.toString();
您可以使用PowerManager使其重新启动这并不保证它会重新启动-操作系统可能会取消它:
如果我尝试/system/bin/su,就会出现以下异常:java.io.IOException:Error running exec。命令:[/system/bin/su,-c,立即重新启动]工作目录:null环境:null每次重新启动仿真器时,您必须键入adb shell chmod 777/dev/tty当然要用串行命令替换/dev/ttydevice@SagarPilkhwal,我没有使用模拟器。我使用的是Galaxy S3 4.4.2如何从外壳中获得答案?谢谢此代码返回以下错误:W/System.err26960:java.io.IOException:write failed:eppe-breaked-pipes这可能有助于解决这个问题,因为它在模拟器上工作。另外,我的galaxy S3是一个根设备,因此我不知道为什么会出现此错误。您是否检查了su文件权限?您是否安装了允许或拒绝su访问的超级用户apk?如果卸载它呢?apk