I am developping an instant messaging app, and want to show a notification when a message is received .
Upon first message, the notification pops up and there is an icon in the status bar, as expected.
After the first message, I update the notification which reflects in the status bar, but the notification does not pop up a second time.
I've tried several things such as changing the notification ID, but that does not work as I need to have only one notification, that is updated and shown, not several notifications.
I am stuck now, please advise.
Edit: Added code.
if (messageNotifications.isEmpty()) {
return null;
}
int messageCount = 0;
for (MessageNotification messageNotification : messageNotifications) {
messageCount += messageNotification.getCount();
}
MessageNotification message = messageNotifications.get(messageNotifications.size() - 1);
boolean showText = false;
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(application);
notificationBuilder.setContentTitle("Secure Messenger");
notificationBuilder.setContentText("Secure Message");
notificationBuilder.setTicker(getText(message, showText));
notificationBuilder.setSmallIcon(getSmallIcon());
notificationBuilder.setLargeIcon(getLargeIcon(message));
notificationBuilder.setColor(ColorManager.getInstance().getAccountPainter().getAccountMainColor(message.getAccount()));
notificationBuilder.setStyle(getStyle(message, messageCount, showText));
notificationBuilder.setContentIntent(getIntent(message));
notificationBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
notificationBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
notificationBuilder.setOnlyAlertOnce(false);
NotificationManager.addEffects(notificationBuilder, messageItem);
return notificationBuilder.build();
private PendingIntent getIntent(MessageNotification message) {
Intent i = new Intent();
i.setAction(Constants.ACTION_SPECIFIC_CHAT);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Notification.FLAG_ONGOING_EVENT);
i.addFlags(Notification.FLAG_NO_CLEAR);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("com.xabber.android.data.user", message.getUser().toString());
i.putExtra("com.xabber.android.data.account", message.getAccount().toString());
i.setData((Uri.parse("custom://" + System.currentTimeMillis())));
return PendingIntent.getActivity(application, UNIQUE_REQUEST_CODE++, i, PendingIntent.FLAG_CANCEL_CURRENT);
}