简体   繁体   English

解锁锁定屏幕

[英]Unlock the lock screen

I am writing an application to manage or customize the unlock screen of the android devices. 我正在编写一个应用程序来管理或自定义Android设备的解锁屏幕。 It works in the following steps: 它的工作原理如下:

  1. The user locks the screen using the power button. 用户使用电源按钮锁定屏幕。
  2. User attempts to unlock the screen, thus pressing the power button again 用户尝试解锁屏幕,从而再次按下电源按钮
  3. My activity pops up -- The screen is still locked 弹出我的活动 - 屏幕仍然锁定
  4. The user answers a question and if the answer is correct the screen unlocks 用户回答问题,如果答案正确,则屏幕解锁

I have created an activity for the third step and added the following code to its onCreate method: 我已经为第三步创建了一个活动,并将以下代码添加到其onCreate方法中:

Window window = getWindow();

window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);

This works properly and exactly as I had hoped. 这正如我所希望的那样正常工作。 My problem is with the fourth step. 我的问题是第四步。 I have searched and found a number of solutions, but none of them are doing it for me. 我搜索并找到了许多解决方案,但他们都没有为我做这些。

How to lock/unlock phone programmatically -- This is just a way to show an activity on top of the lock screen. 如何以编程方式锁定/解锁手机 - 这只是一种在锁定屏幕上显示活动的方法。 It does not unlock it. 它没有解锁它。

Android screen lock/ unlock programatically -- This solution is not only deprecated but it's also really unreliable. Android屏幕锁定/解锁程序 - 此解决方案不仅被弃用,但它也非常不可靠。 It does not unlock the screen, but creates another lock and unlocks that. 它不会解锁屏幕,但会创建另一个锁并解锁。 So using this you can access the applications but it's impossible to access the sensitive settings. 因此,使用此功能可以访问应用程序,但无法访问敏感设置。 (Try it!) (试试吧!)

I tried registering my application as a device administrator. 我尝试将我的应用程序注册为设备管理员。 That didn't help me as well. 这对我也没有帮助。 I can change the setting but I cannot unlock the screen. 我可以更改设置但无法解锁屏幕。

mehrdadjg mehrdadjg

I looked Android Api Source Code(level 23) I don't know how to use KeyguardService's methods with device administrator or root permissions but Android use this service(com.android.systemui.keyguard.KeyguardService.java). 我查看了Android Api源代码(级别23)我不知道如何将KeyguardService的方法与设备管理员或root权限一起使用,但Android使用此服务(com.android.systemui.keyguard.KeyguardService.java)。 Android bind this service(IPC with aidl file) and use it. Android绑定此服务(IPC与aidl文件)并使用它。

The other side... 另一边...

Keyguard controller class, its name is KeyguardViewMediator. Keyguard控制器类,其名称为KeyguardViewMediator。 Under "com.android.systemui.keyguard" package. 在“com.android.systemui.keyguard”包下。 ( Maybe review this lines 1157, 1433) (也许回顾这一行1157,1433)

I don't know how to make unlock action, but Android use this class. 我不知道如何进行解锁操作,但Android使用此类。

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

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