android應用程序中使用root權限

要在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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章