Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Activation of the system key lock (aka lock screen)

I have to activate android's system key lock (the one you get when you press the power off/hang up button). See here:

img

I already browsed the docs but everything I found was PowerManager and KeyguardManager. Both seem not to be the solution :-(.

So, does everyone know how to achieve that from a android application? (If special permissions are required, that is no problem but changing the device's settings is not a solution...)

EDIT: Or does someone know that this is definitely not possible at all? Btw. craigs solution with sending keys does not work anymore (see comments).

like image 315
Johannes Weiss Avatar asked Apr 09 '09 10:04

Johannes Weiss


People also ask

How do I disable screen lock on Android?

How to remove Screen Lock on your Android phone. Tap Settings > Security > Screen Lock. If prompted, enter your current lock screen code > None > Delete.

What is lock screen on Android?

Android lock screens let users set a numerical passcode, password, or a pattern to protect their phone's data, or these days a fingerprint or face print. Your phone's SIM card might also have a separate PIN code set to block a thief from ejecting and physically stealing your phone number.


3 Answers

I have been searching for an answer to the exact same question for a while. Apparently, after 2.0 onwards the device manager privileges for the app level were removed. But with Froyo - 2.2 the device policy manager is revealed granting us developers a multitude of administrative level controls.

http://developer.android.com/guide/topics/admin/device-admin.html

like image 84
Orkun Ozen Avatar answered Nov 16 '22 22:11

Orkun Ozen


What you're looking for is the reenableKeyguard() method in KeyguardManager.KeyguardLock my friend !

like image 31
sthg Avatar answered Nov 16 '22 23:11

sthg


Looks like the screen lock function is performed using the method:

public void goToSleep(long time)

method in PowerManager.java. It's possible to get a reference to it in this fashion:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

However this requires the permission

android.permission.DEVICE_POWER

which is a level 2 permission available to the system only.

So looks like this isn't doable. This is for version 1.1 only, I don't know for 1.5.

like image 1
JRL Avatar answered Nov 16 '22 22:11

JRL