I tried to lock the device after my alarm is stopped through the following code.
mDevicePolicyManager = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mComponentName = new ComponentName(this,AlarmAdminReceiver.class);
Intent adminIntent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
adminIntent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,mComponentName);
adminIntent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,description);
startActivityForResult(adminIntent,1);
mDevicePolicyManager.lockNow();
I have done entry in manifest file as follows :
<receiver
android:name=".AlarmAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<meta-data
android:name="device_admin"
android:resource="@xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
and device_admin.xml file is
<device-admin xmlns:android="http://ift.tt/nIICcg" >
<uses-policies>
<force-lock />
</uses-policies>
</device-admin>
But when trying to lock the device exception is thrown:
05-04 16:42:06.046 E/AndroidRuntime(23159): Caused by: java.lang.SecurityException: No active admin owned by uid 10237 for policy #3 05-04 16:42:06.046 E/AndroidRuntime(23159): at android.os.Parcel.readException(Parcel.java:1540) 05-04 16:42:06.046 E/AndroidRuntime(23159): at android.os.Parcel.readException(Parcel.java:1493) 05-04 16:42:06.046 E/AndroidRuntime(23159): at android.app.admin.IDevicePolicyManager$Stub$Proxy.lockNow(IDevicePolicyManager.java:3509) 05-04 16:42:06.046 E/AndroidRuntime(23159): at android.app.admin.DevicePolicyManager.lockNow(DevicePolicyManager.java:1506)
Please guide me on this to proceed further. Am I using the correct way to get authority for device to lock ?
Aucun commentaire:
Enregistrer un commentaire