开发者

Lock device using DeviceAdminReceiver

开发者 https://www.devze.com 2023-01-30 22:31 出处:网络
i am try to lock the device using DeviceAdminReceiver and try to enable administration like following:

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(DevicePo开发者_Go百科licyManager.EXTRA_ADD_EXPLANATION, "Additional text explaining why this needs to be added.");   startActivity(intent);
 }

and getting error something like the following:

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

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


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.

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>

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>


Best tutorial on device administration: http://rootfs.wordpress.com/2010/09/09/android-make-your-application-a-device-administrator/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号