ITeye博客

android应用程序中使用root权限

aking86 · 2012-03-21 06:00 · 移动开发 · Markdown

要在android应用程序中使用root权限,那么运行程序的设备必须具有root权限。

    http://www.eoeandroid.com/code/2012/0320/973.html

 

写道

public static boolean runRootCommand(String command) {
String TAG = "";
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command + "\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {
Log.d(TAG,
"the device is not rooted, error message: "
+ e.getMessage());
return false;
} finally {
try {
if (os != null) {
os.close();
}
if (process != null) {
process.destroy();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。