1. 分为动态注册和静态注册, 静态注册在清单文件里配置即可.动态创建为代码手动添加. 在锁屏广播中, 使用静态创建消息接受不成功, 原因未知. 动态即可. 代码如下:
public class LockScreenReceiver extends BroadcastReceiver{
//....
}
3. 清单文件, 添加锁屏action,静态创建. 但不响应.
<receiver android:name="com.example.mobilesafe.receiver.LockScreenReceiver" >
<intent-filter android:priority="1000">
<action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
4. 动态创建,消息OK
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
LockScreenReceiver receiver = new LockScreenReceiver();
registerReceiver(receiver, filter);