监听屏幕SCREEN_ON和SCREEN_OFF这两个action,实现屏幕锁定状态的监听,从而实现自己的锁屏效果,奇怪的是,这两个action只能通过代码的形式注册,才能被监听到,使用AndroidManifest.xml 完全监听不到。查了一下,发现这是PowerManager那边在发这个广播的时候,做了限制,限制只能有register到代码中的receiver才能接收。
- privatevoidregisterScreenActionReceiver(){
- finalIntentFilterfilter=newIntentFilter();
- filter.addAction(Intent.ACTION_SCREEN_OFF);
- filter.addAction(Intent.ACTION_SCREEN_ON);
- registerReceiver(receiver,filter);
- }
- privatefinalBroadcastReceiverreceiver=newBroadcastReceiver(){
- @Override
- publicvoidonReceive(finalContextcontext,finalIntentintent){
- //Doyouractionhere
- }
- };