Android获取超级管理员权限

1.定义特殊的广播接收者,系统超级管理员的广播接收者

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

2.在AndroidManifest.xml文件中,注册超级管理员的广播接收者

<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中创建策略声明xml

<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
    <force-lock/><!--强制锁屏-->
    <wipe-data/><!--清除数据-->
    <reset-password/><!--重置密码-->
    ...
</uses-policies>

猜你喜欢

转载自blog.csdn.net/gengkui9897/article/details/81488753