start activity even when phone is locked

此生再无相见时 提交于 2019-12-12 00:17:47

问题


I would like to start an activity like the one used when an alarm starts ringing and a dialog dismiss appears even when the phone is locked and I am able to click it. I have this code from this site but I don't know how to call it when I extend using broadcastreceiver. It always says

the method getWindow() is undefined type for...

I always seemed to get this error everytime I code, what does that mean.

public void unlockScreen() {
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            + WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            + WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}

回答1:


Register boradcast reciever for SCREEEN_ON intent. As screen gets on your braodcast reciever onRecieve(..) will execute, Start your actitvity with flags as you have written in your post in onRecieve method.



来源:https://stackoverflow.com/questions/14549938/start-activity-even-when-phone-is-locked

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