I receive push notifications with data(intent). If I received two or more notifications with different ids, but open one Activity and ids are same. For example, I receive three notifications with different id=1,2,3. But when Activity is started use one id = 3. When I click first or second notification with ids 1 and 2, open Activity with id 3.Can you help understand my mistake in the code?
NOTIFICATION_ID ++;
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(msg.getString("title"))
.setContentText(msg.getString("message"))
.setDefaults(Notification.DEFAULT_SOUND)
.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(Picasso.with(getApplicationContext()).load(msg.getString("icon")).get()).setSummaryText(msg.getString("message")))
.setAutoCancel(true);
Log.e("msg---",msg.toString());
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(this, ActivityDetail.class));
// intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(Keys._PostId,msg.getString("id"));
intent.putExtra(Keys._Image, msg.getString("icon"));
intent.putExtra(Keys._PostType, msg.getString("post_type"));
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Create your PendingIntent
like this and do a trick
PendingIntent contentIntent = PendingIntent.getActivity(this, (int) (Math.random() * 100), intent, PendingIntent.FLAG_UPDATE_CURRENT);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With