Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 856
BBoom Avatar asked Oct 15 '22 05:10

BBoom


1 Answers

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.

like image 82
Olle Avatar answered Oct 20 '22 17:10

Olle