jeudi 28 mai 2015

Not able to launch device administrator activity from my service class (Android Lollipop)

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 administratior window, but it is unchecked as a device admin.

Aucun commentaire:

Enregistrer un commentaire