Android手機獲取root權(quán)限并實現(xiàn)關(guān)機重啟功能的方法
本文實例講述了Android手機獲取root權(quán)限并實現(xiàn)關(guān)機重啟功能的方法,是Android程序設(shè)計中非常常見的重要功能?,F(xiàn)分享給大家,供大家在Android程序開發(fā)中參考之用。
具體功能代碼如下:
/*
* 執(zhí)行命令
* @param command
* 1、獲取root權(quán)限 "chmod 777 "+getPackageCodePath()
* 2、關(guān)機 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程序設(shè)計起到一定的幫助作用。
相關(guān)文章
Android apk完整性檢測的實現(xiàn)思路和代碼實現(xiàn)
這篇文章主要介紹了Android apk完整性檢測的實現(xiàn)思路和代碼實現(xiàn),本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2023-12-12
學(xué)習(xí)Android Material Design(RecyclerView代替ListView)
Android Material Design越來越流行,以前很常用的 ListView 現(xiàn)在也用RecyclerView代替了,實現(xiàn)原理還是相似的,感興趣的小伙伴們可以參考一下2016-01-01
Android之Viewpager+Fragment實現(xiàn)懶加載示例
本篇文章主要介紹了Android之Viewpager+Fragment實現(xiàn)懶加載示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-03-03
Android應(yīng)用 坐標(biāo)系詳細(xì)介紹
這篇文章主要介紹了 Android 坐標(biāo)系的相關(guān)資料,本文對Android 坐標(biāo)系的知識做了詳細(xì)解讀,需要的朋友可以參考下2016-11-11
Android Recyclerview實現(xiàn)水平分頁GridView效果示例
本篇文章主要介紹了Android Recyclerview實現(xiàn)水平分頁GridView效果示例,具有一定的參考價值,有興趣的可以了解一下2017-08-08
Android 判斷網(wǎng)絡(luò)狀態(tài)實例詳解
這篇文章主要介紹了Android 判斷網(wǎng)絡(luò)狀態(tài)實例詳解的相關(guān)資料,需要的朋友可以參考下2017-04-04
Android程序報錯程序包org.apache.http不存在問題的解決方法
這篇文章主要介紹了Android程序報錯"程序包org.apache.http不存在——Android 6.0已經(jīng)不支持HttpClient" 問題的解決方法,感興趣的小伙伴們可以參考一下2016-06-06

