How to know whether the phone is locked mode

拟墨画扇 提交于 2019-12-12 09:53:12

问题


HI guys is there a way for me to know whether the phone is in lock state?


回答1:


Have your app listen our for the ACTION_SCREEN_OFF broadcast. More information here.

public class ScreenReceiver extends BroadcastReceiver {     

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
                //screen locked                
            } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
                //screen unlocked   
            }
        }

}

You might also want to receive information of when the user gets past the keyguard by registering for the ACTION_USER_PRESENT broadcast.



来源:https://stackoverflow.com/questions/6011166/how-to-know-whether-the-phone-is-locked-mode

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