锁屏时如何显示Activity?
我的应用程序在汽车对接事件中启动,我想在插入设备时唤醒手机(由系统完成)并解锁屏幕。
有可能吗?
My application is launched on car docking event, I want to wake up phone (done by system) and unlock screen when I plug my device.
Is it posssible ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我用于将活动提升到最高水平
I'm use for upping activity to top level
使用 Activity.getWindow() 获取 Activity 的窗口;使用 Window.addFlags() 在 WindowManager.LayoutParams 中添加您想要的以下标志: FLAG_DISMISS_KEYGUARD,FLAG_SHOW_WHEN_LOCKED, FLAG_TURN_SCREEN_ON
这就是标准车载底座的方式(和桌面底座)应用程序实现了此行为。
Use Activity.getWindow() to get the window of your activity; use Window.addFlags() to add whichever of the following flags in WindowManager.LayoutParams that you desire: FLAG_DISMISS_KEYGUARD, FLAG_SHOW_WHEN_LOCKED, FLAG_TURN_SCREEN_ON
This is how the standard car dock (and desk dock) app implements this behavior.
您只能将
FLAG_DISMISS_KEYGUARD
用于没有启用安全功能的锁(例如图案锁)的手机。FLAG_SHOW_WHEN_LOCKED
只会将您当前的 Activity 置于顶部,如果用户尝试移动到其他地方,他将必须解锁屏幕。或者,您可以在清单中添加权限:
并且在创建活动中添加权限:
You will be able to use
FLAG_DISMISS_KEYGUARD
only for phones which do not have security enabled locks like pattern lock.FLAG_SHOW_WHEN_LOCKED
will only bring your current Activity on the top, if user tries to move elsewhere, he will have to unlock the screen.Alternatively, you can add permission in your manifest:
And, in your activity on create:
当使用锁定图案或密码输入时,我还需要添加以下内容,因为屏幕会在不到 5 秒的时间内关闭:
When using a lock pattern or a pin entry I needed to add the following as well because the screen turned off in less than 5 seconds: