使用DeviceAdminReceiver锁定装置 [英] Lock device using DeviceAdminReceiver

查看:164
本文介绍了使用DeviceAdminReceiver锁定装置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是尝试使用DeviceAdminReceiver锁定设备并尝试启用管理类似以下内容:

i am try to lock the device using DeviceAdminReceiver and try to enable administration like following:

if (!mDPM.isAdminActive(mDeviceAdminSample)) {
  Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN)
  intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
  intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added.");   startActivity(intent);
 }

和得到错误类似如下:

错误/错误(1022):   java.lang.SecurityException异常:无活动   管理员通过UID 10045政策#拥有3

ERROR/Error(1022): java.lang.SecurityException: No active admin owned by uid 10045 for policy #3

请给我一些code解决方案,以及如何使行政许可。

kindly give me some code solutions and how to enable the administration permission.

推荐答案

通过你的错误信息来看,似乎你可能已经忘记设置你的 device_admin_sample.xml 问该策略要使用。

Judging by your error message it seems that you may have forgotten to set your device_admin_sample.xml to ask for the policy you wish to use.

举例来说,如果你的的Andr​​oidManifest.xml 您有以下接收器$ C $下 DeviceAdminSample

For instance if in your AndroidManifest.xml you have the following receiver code for DeviceAdminSample.

<receiver android:name=".app.DeviceAdminSample"
          android:label="@string/sample_device_admin"
          android:description="@string/sample_device_admin_description"
          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>

然后确保您还设置您的 device_admin_sample.xml 下面的XML,以便您可以使用每个设备管理的能力。

Then make sure that you also set your device_admin_sample.xml to the following xml so that you can use each of the device admin's abilities.

<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>

这篇关于使用DeviceAdminReceiver锁定装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆