简体   繁体   English

如何以编程方式禁用解锁屏幕

[英]How to disable unlocking screen programmatically

  1. I need to lock the Android phone when the user leaves a defined WiFi area 当用户离开定义的WiFi区域时,我需要锁定Android手机
  2. I need to prevent the user from unlocking the phone when he/she is out side the defined WiFi area 当他/她在定义的WiFi区域外时,我需要阻止用户解锁手机
  3. I need to unlock the phone when user is back to the WiFi area 当用户回到WiFi区域时,我需要解锁手机

I guess list items 1 and 3 can be done programmatically. 我猜列表项1和3可以通过编程方式完成。

Is it possible to do the 2 nd item? 是否有可能做第二项?

Locking can be done using this method: How to lock the screen of an android device Unlocking look here: How to display Activity when the screen is locked? 可以使用以下方法锁定如何锁定Android设备的屏幕解锁看这里: 如何在屏幕锁定时显示活动?

For your problem 2, i see 2 solutions 对于你的问题2,我看到2个解决方案

a. 一种。 If the user unlocks the screen, a message is fired: check at that moment if you are in the area and if not, instantly lock again 如果用户解锁屏幕,则会触发一条消息:如果您在该区域,请检查当时是否存在,如果没有,请立即再次锁定

b. create your own locksreen with no possibility to unlock yourself 创建自己的锁屏,无法解锁自己

I need to prevent the user from unlocking the phone when he/she is out side the defined WiFi area 当他/她在定义的WiFi区域外时,我需要阻止用户解锁手机

Fortunately, this is not supported, for obvious security reasons. 幸运的是,出于明显的安全原因,这不受支持。

You are welcome to create your own home screen that offers different behavior when inside/outside a defined area and use that in lieu of trying to prevent a phone from being unlocked. 我们欢迎您创建自己的主屏幕,在定义区域内/外提供不同的行为,并使用它来代替试图阻止手机解锁。 However, the user is welcome to remove that home screen by booting their device into safe mode and uninstalling your app. 但是,欢迎用户通过将设备启动到安全模式并卸载应用程序来删除该主屏幕。

I had done similar thing in past but dont have the code right now so cant help in that respect. 我过去做过类似的事情,但现在没有代码,所以在这方面无法提供帮助。 What I did is implement the app as Car Dock that will make the Home button override unless car-dock mode is dis-abled. 我所做的是将应用程序实现为Car Dock,它将使Home按钮覆盖,除非禁用了car-dock模式。 I hope this will help, for code google it you definitely find resources 我希望这会有所帮助,对于代码谷歌你肯定会找到资源

I guess this will help you out. 我想这会帮到你。 This is just for Disabling the Lock Programmatically . 这仅适用于以Programmatically Disabling锁定。 Disable Screen Lock 禁用屏幕锁定

private Window w;

public void onResume() { public void onResume(){

    w = this.getWindow();
    w.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
    w.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    w.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
    super.onResume();       
    tToast("onResume");
}

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

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