BBoom
BBoom

Reputation: 1949

Locking an android phone (lock pattern or similar)

Since LOCK_PATTERN_ENABLED was moved to Settings.Secure in Froyo my app can no longer lock the screen...

Does anyone know a workaround for this? Any way that my app can instantly lock the screen? No matter if its the autolock pattern or some kind of custom lock screen...

Upvotes: 5

Views: 2338

Answers (1)

Olle
Olle

Reputation: 490

This is a little cumbersome...

If you add a DeviceAdminReceiver to your app and the user enables it the security settings then you are allowd to call

DevicePolicyManager dpm = 
    (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
dpm.lockNow();

to lock the device immediately.

If you don't have a DeviceAdminReceiver in your app the call to .lock() will cause a SecurityException.

Upvotes: 4

Related Questions