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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With