必须动态注册才可以监听到
必须动态注册才可以监听到
必须动态注册才可以监听到
Intent.ACTION_SCREEN_OFF
Intent.ACTION_SCREEN_ON
Intent.ACTION_USER_PRESENT
- 广播ScreenBroadcastReceiver
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.example.util.LogUtil;
/**
* @author master
* @date 2018/1/23
*/
public class ScreenBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
LogUtil.e("广播Action = " + action);
if (action.equals(Intent.ACTION_SCREEN_OFF)) {
LogUtil.e("锁屏");
} else if (action.equals(Intent.ACTION_SCREEN_ON)) {
LogUtil.e("解锁");
}else if(action.equals(Intent.ACTION_USER_PRESENT)){
LogUtil.e("开屏");
}
}
}
ScreenBroadcastReceiver screenBroadcastReceiver = new ScreenBroadcastReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_USER_PRESENT);
getApplicationContext().registerReceiver(screenBroadcastReceiver, filter);
2018-01-26
网友评论