美文网首页
Android设备管理器

Android设备管理器

作者: 小白cz | 来源:发表于2019-02-03 10:54 被阅读0次

创建清单

支持下列内容(https://img.haomeiwen.com/i4191132/a854dd94c76c5cbe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

以下是设备管理示例清单的摘录:

        <receiver android:name="packageName.DeviceAdminReceiver子类"
            android:permission="android.permission.BIND_DEVICE_ADMIN"
            android:label="设备管理器广播接收">
            <meta-data android:name="android.app.device_admin"
                android:resource="@xml/device_admin(跟下面配置文件相同就行)" />
            <intent-filter>
                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
            </intent-filter>
        </receiver>

res/xml新建一个device_admin.xml配置文件(跟元数据一样)

<?xml version="1.0" encoding="utf-8"?>
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
    <!--获取管理器权限-->
    <uses-policies>
        <force-lock/>
        <limit-password />
        <watch-login />
        <reset-password />
        <wipe-data />
        <expire-password />
        <encrypted-storage />
        <disable-camera />
    </uses-policies>
</device-admin>

通过代码调起授权

        final DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        final ComponentName name = new ComponentName(context, DeviceAdminReceiver.class);
        if (dpm == null) {
            return;
        }
        if (!dpm.isAdminActive(name)) {
            Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
            intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, name);
            context.startActivity(intent);  //这里可替换成接受返回值
        }

授权后就可以使用DevicePolicyManager的管理API了

附上官方链接:https://developer.android.google.cn/guide/topics/admin/device-admin#java

相关文章

网友评论

      本文标题:Android设备管理器

      本文链接:https://www.haomeiwen.com/subject/cxdysqtx.html