问题:单击任何通知会将数据带到最新通知。 (以防屏幕上有来自我的应用程序的多个通知)
我希望在单击任何通知时提取与之相关的数据。
intentscore = new Intent(this, Main.class);
intentscore.putExtra("type", messageBody);
intentscore.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
String id = "id_product";
CharSequence name = "Product";
String description = "Notifications regarding our products";
int importance = NotificationManager.IMPORTANCE_MAX;
@SuppressLint("WrongConstant") NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
notificationManager.createNotificationChannel(mChannel);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), "id_product")
.setSmallIcon(R.drawable.ic_logo) //your app icon
.setBadgeIconType(R.drawable.ic_logo) //your app icon
.setChannelId(id)
.setContentTitle(messageTitle)
.setAutoCancel(true)
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, intentscore, PendingIntent.FLAG_UPDATE_CURRENT))
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(i)
.setBigContentTitle("My Application"))
.setContentText(messageBody)
.addAction(R.drawable.ic_remove_red_eye_black_24dp, "Read Article", PendingIntent.getActivity(getApplicationContext(), 0, intentscore, PendingIntent.FLAG_UPDATE_CURRENT))
.addAction(R.drawable.ic_close_black_24dp, "Delete", btPendingIntent)
.setWhen(System.currentTimeMillis())
.setOngoing(true);
notificationManager.notify(Integer.parseInt(idNotify), notificationBuilder.build());