Reputation: 527
I have issue in notification i am using firebase for notification.
Scenario is - when notification received it has two action button accordingly notification will redirect but i didn't perform any operation and i received second notification in that case intent which i set for second notification will loss. It happens only when both notification redirect to the same activity but performs different operation.
here is my code for create notification.
private void createNotification(Map<String, Object> dataMap) {
final String type = dataMap.get("type") + "";
if (CommonUtil.isEmpty(type)) {
return;
}
final FirebaseService.NotificationType notificationType = FirebaseService.NotificationType.valueOf(type);
final String alert = dataMap.get("alert") + "";
String title = dataMap.get("title") + "";
String notificationMessage = alert;
notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
unreadNotifications.add(0, notificationMessage);
android.support.v4.app.NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
if (unreadNotifications.size() > 1) {
inboxStyle.setBigContentTitle("MyApp");
for (String unreadNotification : unreadNotifications) {
inboxStyle.addLine(unreadNotification);
}
inboxStyle.setSummaryText(unreadNotifications.size() + " new notifications.");
}
Intent intent;
intent = new Intent(app, LandingActivity.class);
if (dataMap.containsKey("code")) {
intent.putExtra(IntentExtras.CODE_FROM_NOTIFICATION, dataMap.get("code") + "");
}
intent.setAction(System.currentTimeMillis() + "");
PendingIntent pendingIntent = TaskStackBuilder.create(app)
.addNextIntent(intent)
.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT);
int icon_one = 0, icon_two = 0;
String actionTextOne = null, actionTextTwo = null;
PendingIntent actionOne = null, actionTwo = null;
Intent intentActionOne = null, intentActionTwo = null;
if (notificationType.equals(NotificationType.REQUEST_RECEIVED)) {
icon_one = R.drawable.cancel;
icon_two = R.drawable.notification_track;
actionTextOne = "Edit";
actionTextTwo = "Cancel";
intentActionOne = new Intent(app, LandingActivity.class);
intentActionOne.putExtra(IntentExtras.CODE_FROM_NOTIFICATION, dataMap.get("code") + "");
intentActionOne.putExtra(IntentExtras.EDIT, true);
intentActionTwo = new Intent(app, LandingActivity.class);
intentActionTwo.putExtra(IntentExtras.CODE_FROM_NOTIFICATION, dataMap.get("code") + "");
intentActionTwo.putExtra(IntentExtras.CANCEL, true);
} else if (notificationType.equals(NotificationType.REQUEST_CANCELED)) {
icon_one = R.drawable.reschedule;
icon_two = R.drawable.help;
actionTextOne = "Reschedule";
actionTextTwo = "Help?";
intentActionOne = new Intent(app, LandingActivity.class);
intentActionOne.putExtra(IntentExtras.RESCHEDULE, true);
intentActionTwo = new Intent(app, LandingActivity.class);
intentActionTwo.putExtra(IntentExtras.HELP, true);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(app)
.setSmallIcon(R.drawable.status_bar_icon)
.setLargeIcon(BitmapFactory.decodeResource(app.getResources(), R.drawable.notifications))
.setContentTitle(title)
.setContentText(alert)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setSound(notificationSound)
.setLights(Color.CYAN, 3000, 3000)
.setPriority(Notification.PRIORITY_HIGH);
if (notificationType.equals(NotificationType.REQUEST_RECEIVED) || notificationType.equals(NotificationType.REQUEST_CANCELED)) {
actionOne = TaskStackBuilder.create(app)
.addNextIntent(intentActionOne)
.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT);
actionTwo = TaskStackBuilder.create(app)
.addNextIntent(intentActionTwo)
.getPendingIntent(1, PendingIntent.FLAG_ONE_SHOT);
builder.addAction(icon_one, actionTextOne, actionOne)
.addAction(icon_two, actionTextTwo, actionTwo);
}
Notification notification = builder.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int smallIconViewId = getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
if (smallIconViewId != 0) {
if (notification.contentIntent != null)
notification.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
if (notification.headsUpContentView != null)
notification.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
if (notification.bigContentView != null)
notification.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
}
}
notification.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify("MyApp", Long.valueOf(System.currentTimeMillis()).intValue(), notification);
}
when i get notification for REQUEST_RECEIVED and didn't perform any click operation and then if next notification received for REQUEST_CANCELED in that case second notification action click performs clicks operation of first notification while action sets for second notification doesn't work.
waiting for your suggestions.
Upvotes: 0
Views: 109
Reputation: 126
I am not 100% sure if it will work, but I would put something like this:
intentActionOne.setAction("ACTION_ONE");
intentActionTwo.setAction("ACTION_TWO");
and/or
actionOne = TaskStackBuilder.create(app)
.addNextIntent(intentActionOne)
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
actionTwo = TaskStackBuilder.create(app)
.addNextIntent(intentActionTwo)
.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT);
Upvotes: 1