Intent intent = new Intent();
intent.putExtra("pushMessage", msg.obj.toString());
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setClass(MyApplication.getInstance(), DispatchNotificationActivity.class);
PendingIntent pi = PendingIntent.getActivity(MyApplication.getInstance(), Integer.parseInt(notificationStateBean.getPushId()), intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification;
String CHANNEL_ID = "report";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String CHANNEL_NAME = "在沃通知";
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
mChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);//设置是否应在锁定屏幕上显示此频道的通知
if (nm != null) {
nm.createNotificationChannel(mChannel);
}
notification = new Notification.Builder(MyApplication.getInstance(), CHANNEL_ID)
.setContentTitle(notificationStateBean.getTitle())
.setContentText(notificationStateBean.getContent())
.setSmallIcon(R.drawable.push_small)
.setContentIntent(pi)
.setVisibility(VISIBILITY_PUBLIC)
.setStyle(new Notification.BigTextStyle().setBigContentTitle(notificationStateBean.getTitle())
.bigText(notificationStateBean.getContent()))
.setWhen(time)
// .setLargeIcon(BitmapFactory.decodeResource(MyApplication.getInstance().getResources(), R.mipmap.ic_launcher))
.build();
notification.flags = Notification.FLAG_AUTO_CANCEL;
} else {
notification = new NotificationCompat.Builder(MyApplication.getInstance().getApplicationContext(), CHANNEL_ID)
.setContentTitle(notificationStateBean.getTitle())
.setContentText(notificationStateBean.getContent())
.setSmallIcon(R.drawable.push_small)
.setContentIntent(pi)
.setVisibility(VISIBILITY_PUBLIC)
.setStyle(new NotificationCompat.BigTextStyle().setBigContentTitle(notificationStateBean.getTitle())
.bigText(notificationStateBean.getContent()))
.setWhen(time)
// .setLargeIcon(BitmapFactory.decodeResource(MyApplication.getInstance().getResources(), R.mipmap.ic_launcher))
.build();
if (PreferenceUtils.getBoolean(MyApplication.getInstance().getApplicationContext(), "openNotificationVoice", true)) {
notification.defaults |= Notification.DEFAULT_SOUND;
} else {
notification.sound = null;
}
if (PreferenceUtils.getBoolean(MyApplication.getInstance().getApplicationContext(), "openNotificationVib", true)) {
notification.defaults |= Notification.DEFAULT_VIBRATE;
} else {
notification.vibrate = null;
}
notification.flags = Notification.FLAG_AUTO_CANCEL;
}
if (nm != null) {
nm.notify(Integer.parseInt(notificationStateBean.getPushId()), notification);
}
对跳转对象需要增加通知id的区分。红色部分改成不同的通知id 即可