Android手機(jī)獲取root權(quán)限并實(shí)現(xiàn)關(guān)機(jī)重啟功能的方法
本文實(shí)例講述了Android手機(jī)獲取root權(quán)限并實(shí)現(xiàn)關(guān)機(jī)重啟功能的方法,是Android程序設(shè)計(jì)中非常常見的重要功能?,F(xiàn)分享給大家,供大家在Android程序開發(fā)中參考之用。
具體功能代碼如下:
/* * 執(zhí)行命令 * @param command * 1、獲取root權(quán)限 "chmod 777 "+getPackageCodePath() * 2、關(guān)機(jī) 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; }
希望本文所述實(shí)例對(duì)大家的Android程序設(shè)計(jì)起到一定的幫助作用。
相關(guān)文章
Android 點(diǎn)擊ImageButton時(shí)有“按下”的效果的實(shí)現(xiàn)
這篇文章主要介紹了 Android 點(diǎn)擊ImageButton時(shí)有“按下”的效果的實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2017-03-03Android DrawableTextView圖片文字居中顯示實(shí)例
在我們開發(fā)中,TextView設(shè)置Android:drawableLeft一定使用的非常多,但Drawable和Text同時(shí)居中顯示可能不好控制,小編想到通過自定義TextView實(shí)現(xiàn),具體詳情大家參考下本文2017-03-03Android繼承現(xiàn)有控件拓展實(shí)現(xiàn)自定義控件textView
這篇文章主要介紹了Android繼承現(xiàn)有控件拓展實(shí)現(xiàn)自定義控件textView的相關(guān)資料,需要的朋友可以參考下2016-04-04Android Intent 用法全面總結(jié)及實(shí)例代碼
這篇文章主要介紹了Android Intent 用法全面總結(jié)的相關(guān)資料,并附實(shí)例代碼,需要的朋友可以參考下2016-09-09Android TreeView效果實(shí)現(xiàn)方法(附demo源碼下載)
這篇文章主要介紹了Android TreeView效果實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了Android TreeView效果的實(shí)現(xiàn)原理與具體技巧,并附帶demo源碼供讀者下載,需要的朋友可以參考下2016-02-02Android 個(gè)人理財(cái)工具二:使用SQLite實(shí)現(xiàn)啟動(dòng)時(shí)初始化數(shù)據(jù)
本文主要介紹 Android 使用SQLite實(shí)現(xiàn)啟動(dòng)時(shí)初始化數(shù)據(jù),這里對(duì)SQLite 的數(shù)據(jù)庫進(jìn)行詳解,附有示例代碼,有興趣的小伙伴可以參考下2016-08-08Android App中讀取XML與JSON格式數(shù)據(jù)的基本方法示例
這篇文章主要介紹了Android App中讀取XML與JSON格式數(shù)據(jù)的基本方法示例,Android中自帶的JSONObject非常好用,需要的朋友可以參考下2016-03-03Android Camera2采集攝像頭原始數(shù)據(jù)
這篇文章主要介紹了Android Camera2采集攝像頭原始數(shù)據(jù)并進(jìn)行手工預(yù)覽的功能實(shí)現(xiàn)原理以及代碼分析,需要的朋友學(xué)習(xí)下吧。2018-02-02WindowManagerService服務(wù)是如何以堆棧的形式來組織窗口
我們知道,在Android系統(tǒng)中,Activity是以堆棧的形式組織在ActivityManagerService服務(wù)中的;在本文中,我們就詳細(xì)分析WindowManagerService服務(wù)是如何以堆棧的形式來組織窗口的2013-01-01Android仿淘寶首頁頭條View垂直滾動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Android仿淘寶首頁頭條View垂直滾動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05