【发布时间】:2011-09-20 18:39:10
【问题描述】:
我想在/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 权限运行二进制文件,有没有其他方法或者我做错了什么?
【问题讨论】:
标签: java android unix android-ndk native