锁屏解锁

Posted 码上加油站

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了锁屏解锁相关的知识,希望对你有一定的参考价值。

package com.example.lock_screen;
import android.app.Activity;
import android.content.IntentFilter;
import android.os.Bundle;
public class MainActivity extends Activity {
  private LockScreenReceiver  lockScreenReceiver;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      //代码中注册
      //节约系统开销
      //创建意图过滤器
      IntentFilter filter = new IntentFilter();
      filter.addAction("android.intent.action.SCREEN_OFF");
      filter.addAction("android.intent.action.SCREEN_ON");
      lockScreenReceiver = new LockScreenReceiver();
      //注册锁屏解锁广播接收者
      registerReceiver(lockScreenReceiver, filter);
   }
   @Override
   protected void onDestroy() {
      super.onDestroy();
      //activity销毁前注销广播
      unregisterReceiver(lockScreenReceiver);
   }
}
package com.example.lockphone;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class LockPhoneReceiver extends BroadcastReceiver{
   @Override
   public void onReceive(Context context, Intent intent) {
      if("android.intent.action.SCREEN_OFF".equals(intent.getAction())){
         System.out.println("锁屏了");
      }else if("android.intent.action.SCREEN_ON".equals(intent.getAction())){
         System.out.println("解锁了");
      }
   }
}

 

以上是关于锁屏解锁的主要内容,如果未能解决你的问题,请参考以下文章

iOS开发-检测程序在前台和后台锁屏解锁的状态

BroadcastReceiver之实现锁屏解锁样例

ios监听锁屏解锁如何实现,需要调用啥方法?

检测手机屏幕是否亮屏解锁

Appium 解决锁屏截屏问题(java篇)

windows锁屏中,怎么实现自动解锁,进入界面