我在设备处于后台时发送通知。通知正在向移动用户发送。但点击通知后它没有取消。仍显示在状态栏中。我将此用于iBeacon发送通知。但我认为,我需要检查deivce是foregraound还是background.If它的前景我们必须取消通知。如果背景我们需要发送通知。我们怎么检查这个?
Intent notifyIntent = new Intent(NotifyDemoActivity.this, NotifyDemoActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivities(
NotifyDemoActivity.this,
0,
new Intent[]{notifyIntent},
PendingIntent.FLAG_UPDATE_CURRENT);
// Intent showIntent = new Intent(this, NotifyDemoActivity.class);
// PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, showIntent, 0);
Notification notification = new Notification.Builder(NotifyDemoActivity.this)
.setSmallIcon(R.drawable.beacon_gray)
.setContentTitle("Welcome")
.setContentText(msg)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build();
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(NOTIFICATION_ID, notification);