मुझे कई सूचनाएं प्राप्त हो रही हैं, जिनमें से प्रत्येक की अपनी विशिष्ट id है।
वांछित परिदृश्य यह है कि प्रत्येक सूचना का अपना अतिरिक्त हो।
लेकिन जब मैं सूचनाओं को बंडल ऑब्जेक्ट में स्टोर/स्टैश करता हूं, तो सभी सूचनाएं समान अतिरिक्त असाइन की जाती हैं -(अर्थात अतिरिक्त जो अंतिम अधिसूचना से संबंधित है)।
मैंने इसकी पुष्टि की है क्योंकि जब मैं किसी सूचना पर क्लिक करता हूं, तो मुझे प्राप्त अंतिम पोस्ट पर भेज दिया जाता है।
जबकि मैं सूचना के अनुरूप पोस्ट पर भेजा जाना चाहता हूं, मैंने अभी-अभी क्लिक किया है।
नीचे प्रासंगिक कोड स्निपेट है: -
public void createNotif(Poste poste, Comment comment, Boolean checkGroupSon) {
if (comment == null) {
emeteur = poste.getEmmet();
message = poste.getTx();
pathImg = poste.getImg();
} else {
emeteur = comment.getEmmet();
message = comment.getComment();
pathImg = comment.getImage();
}
//onDismiss Intent
Intent intent = new Intent(mContext, NotificationControllerReceiver.class);
PendingIntent mBroadcastIntentController = PendingIntent.getBroadcast(mContext, 0, intent, 0);
Intent notificationIntent = new Intent(mContext, CommentPhotoActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Intent.FLAG_ACTIVITY_CLEAR_TASK|
notificationIntent.putExtra("pid", poste.getId());
PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//TEST notification.setLatestEventInfo(getApplicationContext(), "YuYu", "Vous avez reçu un nouveau poste", contentIntent);
//TEST notification.flags = Notification.FLAG_AUTO_CANCEL;
//TEST
// NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext()).setContentTitle("Poste: "+emeteur).setSmallIcon(R.drawable.ic_launcher).setContentIntent(contentIntent).setContentText(message).setDeleteIntent(mBroadcastIntentController).setPriority(Notification.PRIORITY_MAX);
NotificationCompat.Builder notificationBuilder = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationBuilder = new NotificationCompat.Builder(mContext, "poste");
if (pathImg == null)
notificationBuilder.setContentTitle(emeteur).setSmallIcon(R.drawable.ic_launcher).setContentIntent(contentIntent).setContentText(emeteur + ": " + message).setDeleteIntent(mBroadcastIntentController).setPriority(NotificationCompat.PRIORITY_MAX);
else
notificationBuilder.setContentTitle(emeteur).setSmallIcon(R.drawable.ic_launcher).setContentIntent(contentIntent).setContentText(emeteur + ": Photo \uD83D\uDCF7 " + message).setDeleteIntent(mBroadcastIntentController).setPriority(NotificationCompat.PRIORITY_MAX);
}
// notificationBuilder.setContentTitle("Poste: "+emeteur).setSmallIcon(R.drawable.ic_launcher).setContentIntent(contentIntent).setContentText(message).setDeleteIntent(mBroadcastIntentController).setPriority(Notification.PRIORITY_MAX);
}
// long[] v = {500,1000};
// notificationBuilder.setVibrate(v);
notifications = null;
boolean b = notifHashMap.containsKey(poste.getId());
if (b) {
notifications = notifHashMap.get(poste.getId());
// Add your All messages here or use Loop to generate messages
if (pathImg == null)
notifications.add(emeteur + ":" + message);
else
notifications.add(emeteur + ": Photo \uD83D\uDCF7 " + message);
notifHashMap.put(poste.getId(), notifications);
} else {
notifications = new ArrayList<String>();
// Add your All messages here or use Loop to generate messages
if (pathImg == null)
notifications.add(emeteur + ":" + message);
else
notifications.add(emeteur + ": Photo \uD83D\uDCF7 " + message);
notifHashMap.put(poste.getId(), notifications);
}
// if (inboxStyle == null)
// inboxStyle = new NotificationCompat.InboxStyle();
//else
inboxStyle = new NotificationCompat.InboxStyle(notificationBuilder);
if (notifications.size() > 1) {
if (poste.getImg() == null)
inboxStyle.setBigContentTitle("Poste:" + poste.getTx());
else
inboxStyle.setBigContentTitle("Poste: \uD83D\uDCF7 " + poste.getTx());
inboxStyle.setSummaryText("Vous avez " + notifications.size() + " notifications.");
for (int i = 0; i < notifications.size(); i++) {
inboxStyle.addLine(notifications.get(i));
}
} else if (notifications.size() == 1) {
inboxStyle.addLine(notifications.get(0));
}
notificationBuilder.setStyle(inboxStyle);
notificationBuilder.setVibrate(new long[]{0L});
//notificationBuilder.setNumber(value++);
if (!checkGroupSon) {
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationBuilder.setSound(alarmSound);
}
NotifManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
/* Create or update. */
mChannel = new NotificationChannel("poste", "YuYu", NotificationManager.IMPORTANCE_LOW);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.canShowBadge();
mChannel.setVibrationPattern(new long[]{ 0 });
mChannel.enableVibration(true);
/* if (!checkGroupSon) {
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
} */
assert NotifManager != null;
notificationBuilder.setChannelId("poste");
// NotifManager.deleteNotificationChannel("poste");
NotifManager.createNotificationChannel(mChannel);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
summaryNotification = new NotificationCompat.Builder(mContext, "poste")
.setSmallIcon(R.drawable.ic_launcher)
.setStyle(new NotificationCompat.InboxStyle()
.addLine("1")
.addLine("2")
.setBigContentTitle("nouveau messages")
.setSummaryText("Nouveau message"))
.setPriority(NotificationCompat.PRIORITY_LOW)
.setGroup("example_group")
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN)
.setGroupSummary(true).build();
}
Notification notification = notificationBuilder.setGroup("example_group").build();
notification.flags = Notification.FLAG_AUTO_CANCEL;
// assert NotifPostMsgManager != null;
//TEST manager.notify(ID_NOTIFICATION, notification);
NotifManager.notify(poste.getId(), notification);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
NotifManager.notify(1, summaryNotification);
}
1 उत्तर
आप अपने NotifManager.notify(1, summaryNotification) //id == 1
में एक ही आईडी का उपयोग कर रहे हैं, इसलिए आपको एक ही इरादे का परिणाम मिलता है, आपको अलग-अलग आईडी का उपयोग करना चाहिए और इसे कुछ सहेजे गए डेटा में sharedPreferences
के रूप में संग्रहीत किया जाना चाहिए।
संबंधित सवाल
नए सवाल
android
एंड्रॉइड Google का मोबाइल ऑपरेटिंग सिस्टम है, जिसका उपयोग प्रोग्रामिंग या डिजिटल डिवाइस (स्मार्टफोन, टैबलेट, ऑटोमोबाइल्स, टीवी, वियर, ग्लास, IoT) को विकसित करने के लिए किया जाता है। एंड्रॉइड से संबंधित विषयों के लिए, एंड्रॉइड-विशिष्ट टैग जैसे कि एंड्रॉइड-इरादे, एंड्रॉइड-गतिविधि, एंड्रॉइड-एडॉप्टर आदि का उपयोग करें। विकास या प्रोग्रामिंग के अलावा अन्य प्रश्नों के लिए, लेकिन एंड्रॉइड फ्रेमवर्क से संबंधित हैं, इस लिंक का उपयोग करें: https: // android.stackexchange.com।