必须动态注册才可以监听到
必须动态注册才可以监听到
必须动态注册才可以监听到
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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。