我正在开发我的第一个Android应用程序,我很好奇是否有任何"标准"方法来执行特权shell命令.我只能够找到这样做的一种方式,通过执行su,然后再追加我的命令stdin的的su过程.
DataOutputStream pOut = new DataOutputStream(p.getOutputStream());
DataInputStream pIn = new DataInputStream(p.getInputStream());
String rv = "";
// su must exit before its output can be read
pOut.writeBytes(cmd + "\nexit\n");
pOut.flush();
p.waitFor();
while (pIn.available() > 0)
rv += pIn.readLine() + "\n";
Run Code Online (Sandbox Code Playgroud)
我已经读过关于包装特权(superuser)调用的内容JNI:这可能吗?如果是这样,一个人将如何完成它?除此之外,是否还有其他方式来调用特权指令Java?
我可以在rooted设备上使用busybox在后台安装apk吗?
我看到类似的东西,但它不起作用
process install;
CommandCapture command = new CommandCapture(0, "chmod 777 /data/app");
RootTools.getShell(true).add(command).waitForFinish();
CommandCapture command2 = new CommandCapture(0, "chmod 777 /system/xbin/busybox");
RootTools.getShell(true).add(command2).waitForFinish();
install = Runtime.getRuntime().exec("/system/xbin/busybox install " + Environment.getExternalStorageDirectory() + "/Download/" + "xxx.apk /data/app/xxx.apk");
Run Code Online (Sandbox Code Playgroud)