引用:http://wiseideal.iteye.com/blog/1166794
转载自:http://dev.10086.cn/cmdn/bbs/thread-37036-1-1.html
- public static boolean runRootCommand(String command) {
- 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;
- }