久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

Android獲取超級(jí)管理員權(quán)限的實(shí)現(xiàn)

瀏覽:2日期:2022-09-26 10:42:56

1.定義特殊的廣播接收者,系統(tǒng)超級(jí)管理員的廣播接收者

public class MyDeviceAdminReceiver extends DeviceAdminReceiver{ @Override public void onReceive(Context context,Intent intent){ //TODO }}

2.在AndroidManifest.xml文件中,注冊(cè)超級(jí)管理員的廣播接收者

<receiver android:name='com.example.receiver.MyDeviceAdminReceiver' android:permission='android.permission.BIND_DEVICE_ADMIN'> <meta-data android:name='android.app.device_admin' android:resource='@xml/device_admin_sample'/> <intent-filter> <action android:name='android.app.action.DEVICE_ADMIN_ENABLED'/> </intent-filter></receiver>

3.在res/xml中創(chuàng)建策略聲明xml

<device-admin xmlns:android='http://schemas.android.com/apk/res/android'><uses-policies> <force-lock/><!--強(qiáng)制鎖屏--> <wipe-data/><!--清除數(shù)據(jù)--> <reset-password/><!--重置密碼--> ...</uses-policies>

補(bǔ)充知識(shí):Android通過代碼獲取ROOT權(quán)限

獲取Android的ROOT權(quán)限其實(shí)很簡(jiǎn)單,只要在Runtime下執(zhí)行命令'su'就可以了。

首先我們需要檢測(cè)是否已經(jīng)有root權(quán)限,判斷代碼如下:

// 判斷是否具有ROOT權(quán)限public static boolean is_root(){ boolean res = false; try{ if ((!new File('/system/bin/su').exists()) && (!new File('/system/xbin/su').exists())){ res = false; } else { res = true; }; } catch (Exception e) { } return res;}

然后我們執(zhí)行獲取root權(quán)限的代碼

// 獲取ROOT權(quán)限public void get_root(){ if (is_root()){ Toast.makeText(mCtx, '已經(jīng)具有ROOT權(quán)限!', Toast.LENGTH_LONG).show(); } else{ try{ progress_dialog = ProgressDialog.show(mCtx, 'ROOT', '正在獲取ROOT權(quán)限...', true, false); Runtime.getRuntime().exec('su'); } catch (Exception e){ Toast.makeText(mCtx, '獲取ROOT權(quán)限時(shí)出錯(cuò)!', Toast.LENGTH_LONG).show(); } }}

以上這篇Android獲取超級(jí)管理員權(quán)限的實(shí)現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 清流县| 米易县| 密云县| 绍兴市| 唐山市| 汉沽区| 三江| 广河县| 无极县| 治多县| 平邑县| 航空| 利川市| 兴城市| 卫辉市| 依兰县| 乐亭县| 新和县| 吴旗县| 尼勒克县| 新沂市| 东乌| 盐城市| 孝昌县| 海宁市| 神木县| 潞城市| 富民县| 黄石市| 喜德县| 新营市| 汝阳县| 泌阳县| 静乐县| 仁布县| 神池县| 涞源县| 阳东县| 益阳市| 涟水县| 临潭县|