6

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.

John Landheer
  • 3,999
  • 4
  • 29
  • 53
Umayal
  • 61
  • 1
  • 1
  • 3
  • Please [follow this Link][1] Hope its will be helpful to you. [1]: http://stackoverflow.com/questions/13450986/device-administrative-android-app-implementation – Caution Continues Nov 19 '12 at 15:20

2 Answers2

8

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>
Anton
  • 12,285
  • 20
  • 64
  • 84
  • Is that need root permission? – Hugo May 30 '13 at 07:41
  • No you do not need to root the android phone. – Anton Jun 01 '13 at 20:58
  • Yes there is a need to press OK from a Dialog. You only have to ask for permission once and from then on it remembers. Here is the link to the Android Device Admin Documentation http://developer.android.com/guide/topics/admin/device-admin.html – Anton Jun 04 '13 at 19:19
  • Thanks for the link.Actually I wanna solve the problem that "fail to connect camera service". But it doesn't work. – Hugo Jun 05 '13 at 09:31
  • From what I can tell that error doesn't sound related to the Device Admin stuff. – Anton Jun 05 '13 at 14:13
  • Yeah,before I think disable Camera with Device Admin can restart the CameraService.But I tried It doesn't work. – Hugo Jun 06 '13 at 02:13
  • Is that possible to disable settings menu ..? – Bivin OC Oct 09 '18 at 09:47
5

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

Syed
  • 550
  • 1
  • 7
  • 22