0

I have been trying to lock my phone programmatically when some particular condition is met. In my case a for loop which loops for 10 times.

Here's what I am doing to lock my phone

private DevicePolicyManager mDevicePolicyManager; 
private ComponentName mComponentName;  

In my onCreate:

mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
mComponentName = new ComponentName(this, AppAdminReceiver.class);

KeyguardManager keyGuardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
lock = keyGuardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();

In one of my func when the for loop loops for 10 times this get executed

lock.reenableKeyguard();
mDevicePolicyManager.lockNow();

But it does'nt seem to work. Can some one help me? And also the KeyGuardLock class has been deprecated I guess. Is there any other way ?

Kara
  • 6,115
  • 16
  • 50
  • 57
ik024
  • 3,566
  • 7
  • 38
  • 61
  • Did you use the USES_POLICY_FORCE_LOCK? – Zohra Khan Mar 27 '14 at 05:41
  • Check this link http://stackoverflow.com/questions/8987847/devicepolicymanager-locknow-is-not-working-for-motorola-tablets – Zohra Khan Mar 27 '14 at 05:44
  • @ZohraKhan Thanks ur reply :) I got it working using this: Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mComponentName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,description); startActivityForResult(intent, ADMIN_INTENT); mDevicePolicyManager.lockNow(); – ik024 Mar 27 '14 at 05:48

0 Answers0