Pari
Pari

Reputation: 1715

Multiple notification on same intent

I am writing an application and in this application I need to set multiple notification with same intent just like open my application whenever user tap on any notification.

All the notification comes on different time and date without having any data but the problem is, if I set two notification for 03:27 PM and 03:28 PM then the first notification (03:27 PM) is canceled (Overwritten by second) and second is working correctly.

I am currently using this code for achieving this goal:

this method is used to set notification from Activity:

 public static void setNotificationOnDateTime(Context context, long fireTime)
     {
         int requestID = (int) System.currentTimeMillis();

         AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
         Intent i = new Intent(context, NotificationReceiver.class);

         PendingIntent pi = PendingIntent.getBroadcast(context, requestID, i, 0);
         am.set(AlarmManager.RTC_WAKEUP, fireTime, pi);
     }

and my NotificationReceiver class look like this:

 NotificationManager nm;

 @Override
 public void onReceive(Context context, Intent intent) {
     Log.w("TAG", "Notification fired...");

     nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

     PendingIntent contentIntent;

     Bundle bundle = intent.getExtras().getBundle("NotificationBundle");
     if(bundle == null)
     {
         contentIntent = PendingIntent.getActivity(context, 0,
                 new Intent(context, SplashScreen.class), 0);
     }

     else
     {
         contentIntent = PendingIntent.getActivity(context, 0,
                 new Intent(context, MenuScreen.class)
         .putExtra("NotificationBundle", bundle), 0);
     }

     Notification notif = new Notification(R.drawable.ic_launcher,
             "Crazy About Android...", System.currentTimeMillis());
     notif.setLatestEventInfo(context, "Me", "Message test", contentIntent);
     notif.flags |= Notification.FLAG_AUTO_CANCEL;
     nm.notify(1, notif);
 }

I alerady spend a lot time on googling and found some solutions but they didn't work for me here is the link of some of them:

android pending intent notification problem

Multiple notifications to the same activity

If any one knows how to do this please help me.

Upvotes: 1

Views: 1670

Answers (3)

class stacker
class stacker

Reputation: 5347

Quote:

Post a notification to be shown in the status bar. If a notification with the same id has already been posted by your application and has not yet been canceled, it will be replaced by the updated information.

But you're always using 1 for the id parameter. Use a unique ID when you post several notifications.

Update If that doesn't help, you can still create Intents which do not compare as being equal, while having an equal effect.

Upvotes: 1

GrIsHu
GrIsHu

Reputation: 23638

Try to set as below :

  contentIntent=PendingIntent.getActivity(p_context, i, new Intent(context, MenuScreen.class),PendingIntent.FLAG_CANCEL_CURRENT);

It might help you.

Upvotes: 0

Tamilselvan Kalimuthu
Tamilselvan Kalimuthu

Reputation: 1532

this may be helpful

notif.flags |= Notification.FLAG_ONGOING_EVENT;

the notification will never close...

Upvotes: 0

Related Questions