发送广播
public void btn1(View view) {
Intent intent = new Intent();
intent.setAction("com.zcb");
sendBroadcast(intent);
}
public void btn2(View view) {
Intent intent = new Intent();
intent.setAction("com.zcb1");
Bundle bundle = new Bundle();
bundle.putString("name","XiaoMing");
intent.putExtras(bundle);
sendOrderedBroadcast(intent,null);
}
开启关闭屏幕通知
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_USER_PRESENT)){
Log.i(TAG, "onReceive: 屏幕亮了");
}else if (action.equals(Intent.ACTION_SCREEN_OFF)){
Log.i(TAG, "onReceive: 屏幕黑了");
}
}