首页 > 代码库 > 锁屏解锁
锁屏解锁
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("解锁了"); } } }
锁屏解锁
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。