Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lock device using 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);
 }

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.

like image 992
Umayal Avatar asked Dec 15 '10 11:12

Umayal


2 Answers

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

like image 26
Syed Avatar answered Sep 19 '22 12:09

Syed


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>
like image 137
Anton Avatar answered Sep 22 '22 12:09

Anton