0

I'm trying to prompt the user with the device administrator activity to enable my application as a device administrator. And here is the code which attempts to call the device administrator activity from my service class:

ComponentName deviceAdmin=new ComponentName(context,DeviceAdminReceiver.class);
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdmin);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Make sure to accept in order to provide support for lock and wipe");
PendingIntent pendingIntent = PendingIntent.getActivity(context, DevicePolicyManagerLockWipeService.RESULT_ENABLE, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
pendingIntent.send();

Android Manifest is as follows;

<receiver android:name=".DeviceAdminReceiver" android:label="DeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN" android:exported="true">
<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>

This works perfectly on any 4.x android versions, but doesn't work on Lollipop version. In lollipop when I kick start my application it looks like it is opening the device admin activity, but immediately the activity animation stops and it closes without prompting the user to enable device admin. However, my application shows up in the settings->security->device administrator window, but it is unchecked as a device admin.

1 Answer 1

3

You may need to remove android:launchMode="singleInstance" from the activity that sends the ACTION_ADD_DEVICE_ADMIN intent in your AndroidManifest.xml

2
  • 1
    ACTION_ADD_DEVICE_ADMIN intent is sent from the service class not from the activity.
    – Chethan
    May 29, 2015 at 2:58
  • 1
    Well that is part of the problem, even on 4.x not having a separate activity to send the intent would not bring up the dialog (at least on devices we use). Make a new activity that does nothing other than send the intent and then launch that activity from your service. May 29, 2015 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.