对设备管理器DeviceAdmin的锁屏学习

来源:互联网 发布:python 手写识别 编辑:程序博客网 时间:2024/06/03 20:01

1.创建DeviceAdminReceiver的子类

如:com.wang.lockscreen.DeviceAdminSample

2.在清单文件中配置广播接收者

<receiver

  android:name="com.wang.lockscreen.DeviceAdminSample"

  android:description="@string/sample_device_admin_description"

  android:lable="@string/sample_device_admin"

  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>

/>

3.配置字符串相关信息

  <string name="activity_sample_device_admin">设备管理员</string>

  <string name="sample_device_admin">管理员</string>

  <string name="sample_device_admin_description">设备管理员提示</string>

4.在res目录下创建xml文件,在其中新增device_admin_sample.xml

<device-admin xmls:android="https://schemas.android.com/apk/res/android">

  <uses-policies>

    <limit-password />

    <watch-login />

    <reset-password />

    <force-lock />

    <wipe-data />

    <expire-password />

    <encrypted-storage />

    <disable-camera />

  </uses-policies>

</device-admin》

5.在代码中创建设备管理器和组件

dpm = (DevicePolicyManager)getSystemService(DEVICE_POLICY_SERVICE);

ComponentName who = new ComponentName(this,DeviceAdminSample.class);

6.写功能

dpm.lockNow();





0 0