Android device policy administration errors

I recently started to learn the Android device policy administration API and ran into a little wall. I have problems with simple device administration. I am pretty sure that this is a problem with manifest recording, however I cannot pinpoint the problem area.

Enter manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example" android:versionCode="1" android:versionName="1.0"> <application android:label="DeviceAdminTrial" android:icon="@drawable/icon" android:debuggable="true"> <activity android:name=".MyActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".Receiver" android:label="device_admin" android:permission="android.permission.BIND_DEVICE_ADMIN"/> <meta-data android:name="android.app.device_admin" android:resource="@xml/device_admin" /> <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/> </intent-filter> </application> </manifest> 

Error message:

 12-25 15:42:38.930: WARN/DeviceAdminAdd(394): Unable to retrieve device policy ComponentInfo{com.example/com.example.Receiver} org.xmlpull.v1.XmlPullParserException: No android.app.device_admin meta-data 

device_admin.xml

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

Way of inclusion:

  enable = (Button)findViewById(R.id.button); enable.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent (DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, receiver); startActivityForResult(intent, 1);//1 is enabled, 0 is disabled. output.setText(""+policymanager.isAdminActive(receiver)); } }); 

And the Receiver class is as basic as the sample found here: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.html

Any help or advice would be greatly appreciated.

+6
android policy device-admin
source share
3 answers

In the manifest:

 <receiver android:name=".Receiver" android:label="device_admin" android:permission="android.permission.BIND_DEVICE_ADMIN"> <meta-data android:name="android.app.device_admin" android:resource="@xml/device_admin" /> <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> </intent-filter> </receiver> 
+5
source share

I had the same problem. MyAdmin class signature must be public static

 public static class MyAdmin extends DeviceAdminReceiver { } 
-2
source share

All Articles