How to detect and control the phone lock/unlock on android?
android
Solution
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.
Problem
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