我想在 /dev/local
运行一个名为 native 的二进制文件(我通过 adb 推送它),具有 root 权限。
为了实现这一点,我编写了以下代码:
try {
root=Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(root.getOutputStream());
DataInputStream osRes = new DataInputStream(root.getInputStream());
os.writeBytes("/data/local/native\n");
os.flush();
TextView output=(TextView)findViewById(R.id.textview);
output.append(osRes.readLine());
root.waitFor();
} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(this, e.toString() , Toast.LENGTH_SHORT).show();
}
这给了我一个NullPointerException
。所以,我尝试将其更改为:
try{
root=Runtime.getRuntime().exec("su");
root.waitFor();
DataOutputStream os = new DataOutputStream(root.getOutputStream());
DataInputStream osRes = new DataInputStream(root.getInputStream());
os.writeBytes("/data/local/native\n");
os.flush();
TextView output=(TextView)findViewById(R.id.textview);
output.append(osRes.readLine());
root.waitFor();
} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(this, e.toString() , Toast.LENGTH_SHORT).show();
}
有了这个,我得到了 BrokenPipe 错误。
请帮助我,我想以 root 权限运行二进制文件,有没有其他方法或者我做错了什么?
最佳答案
尝试运行 su -c/path/to/executable
。
关于java - 使用 root Android 应用程序运行二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6446969/