How to launch an activity when lock screen is enabled?

大城市里の小女人 提交于 2019-12-08 09:10:44

问题


How do you launch an activity when the lock screen is enabled? I want to be able to launch an activity as a result of the screen being locked. I already no I can make an activity work on top of the lock screen using WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED but it is a little unclear to me how to start the activity when the screen is locked. Do I need a service to be running that listens for the screen to lock and then launches the activity?


回答1:


When the lock screen is enabled, you should programmatically unlock first the screen and launch the activity you want. After that, you can lock again the screen or do whatever you want. Maybe you can use a broadcast listener for lock screen if there is. You could try ACTION_SCREEN_OFF or create a service.



来源:https://stackoverflow.com/questions/5161699/how-to-launch-an-activity-when-lock-screen-is-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!