简体   繁体   English

如何在android上检测和控制手机锁定/解锁?

[英]How to detect and control the phone lock/unlock on 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请帮帮我

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.对于检测,你可以按照这个教程http://chandan-tech.blogspot.fr/2010/10/handling-screen-lock-unlock-in-android.html ,很清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM