2_deviceadmin步骤 :
1.创建 MyAdmin 的广播接受者 继承 DeviceAdminReceiver

<receiver android:name=".MyAdmin">            <meta-data android:name="android.app.device_admin" android:resource="@xml/my_admin" />            <intent-filter>                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />            </intent-filter>        </receiver>

my_admin.xml

<?xml version="1.0" encoding="utf-8"?><device-admin xmlns:android="http://schemas.android.com/apk/res/android">        <uses-policies>                <limit-password />                <watch-login />                <reset-password />                <force-lock />                <wipe-data />        </uses-policies></device-admin>

2.获取IDevicePolicyManager

Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);IBinder binder = (IBinder) method.invoke(null,new Object[] { Context.DEVICE_POLICY_SERVICE });mService = IDevicePolicyManager.Stub.asInterface(binder);

3.注册广播接受者为admin设备

ComponentName mAdminName = new ComponentName(this, MyAdmin.class);if (mService != null) {        if (!mService.isAdminActive(mAdminName)) {                    Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);                    intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,mAdminName);                    startActivity(intent);                }}

更多相关文章

  1. Android中的服务有几种,具体实现步骤,这几种之间的区别
  2. Android自定义View的基本步骤和使用自定义属性
  3. Android multiDex 分包步骤
  4. Android 使用 AndroidTestCase 的步骤
  5. Android Studio 配置 androidAnnotations框架详细步骤
  6. Ubuntu 14.04 64位机上配置Android Studio操作步骤

随机推荐

  1. Others1
  2. 自定义Android(安卓)标题栏TitleBar布局
  3. 把文件存放在SDCard
  4. Android(安卓)8.0系统Bug Only fullscree
  5. Android(安卓)wifi框架
  6. [转] Android(安卓)achartengine统计图
  7. Android艺术探究二次学习笔记
  8. Android(安卓)代码模拟ListView item的点
  9. Android:调试之DDMS
  10. 简单的三方登录SDK示例,Android(安卓)Acti