Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect and control the phone lock/unlock on android?

Tags:

android

I want to make that the phone ask a question(from database) when the phone is locked (locked = the keyboard is locked ) and the user want to unlock. If the answer is correct then the phone is unlocked, else the phone ask another question.

I don't know how to detect the unlock and unlock/lock the phone when I want.

Please, help me

like image 882
TKA Avatar asked Dec 03 '13 16:12

TKA


1 Answers

You may want to have a look on Device Policy Manager and Device Admin tutorial. You can lock the screen by a simple sample of code like:

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

For the detection, you can follow this tutorial http://chandan-tech.blogspot.fr/2010/10/handling-screen-lock-unlock-in-android.html, it's very clear.

like image 125
Quentin Klein Avatar answered Nov 15 '22 12:11

Quentin Klein