1

I am using Phonegap with GCM plugin to show GCM notification. I am able to display notification correctly but I am not able to show multiple notification. I tried Notification passes old Intent Extras but No results yet. Please help.

private static void generateNotification(Context context, String message) {
        int icon = R.drawable.ic_launcher;
        long when = System.currentTimeMillis();
        NotificationManager notificationManager = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new Notification(icon, message, when);

        String title = context.getString(R.string.app_name);
        int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);

       // saveCallIntent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
        Intent notificationIntent = new Intent(context, JainDharma.class);
        // set intent so it does not start a new activity
        //notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent =
                PendingIntent.getActivity(context, iUniqueId, notificationIntent, 0);
        //PendingIntent contentIntent = PendingIntent.getActivity(context, UNIQUE_INT_PER_CALL, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        // Play default notification sound
        notification.defaults |= Notification.DEFAULT_SOUND;

        //notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");

        // Vibrate if vibrate is enabled
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notificationManager.notify(0, notification);      
Community
  • 1
  • 1
  • Please provide more details about your problem. Are you getting any error messages. What have you tried. Have you tried debugging? What did you learn from doing that? Posting a new question on StackOverflow should be your last resort after you have tried and researched the problem all you can. Provide all information you gather during that process here, then. – Chris Pratt Jun 17 '13 at 19:07

1 Answers1

2

If you mean that the last notification overrides the previous one, and you wish to change it, you need to change the following :

notificationManager.notify(0, notification);

Use a different id (instead of 0) for each notification and you'll see all of them.

However, you might want to reconsider whether it's such a good idea to show multiple notifications for the same app. I would find that annoying as a user of your app.

Eran
  • 387,369
  • 54
  • 702
  • 768