且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何知道手机是否处于锁定模式?

更新时间:2022-04-28 01:12:13

让您的应用收听我们的 ACTION_SCREEN_OFF 广播.详细信息此处.

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   
            }
        }

}

您可能还想通过注册 ACTION_USER_PRESENT 广播.

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