本文實例講述了Android手機獲取root權限并實現關機重啟功能的方法,是Android程序設計中非常常見的重要功能。現分享給大家,供大家在Android程序開發中參考之用。
具體功能代碼如下:
/* * 執行命令 * @param command * 1、獲取root權限 "chmod 777 "+getPackageCodePath() * 2、關機 reboot -p * 3、重啟 reboot */public static boolean execCmd(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) { return false; } finally { try { if (os != null) { os.close(); } if(process != null) { process.destroy(); } } catch (Exception e) { e.printStackTrace(); } } return true;}
希望本文所述實例對大家的Android程序設計起到一定的幫助作用。
新聞熱點
疑難解答
圖片精選