nicBBB
nicBBB

Reputation: 257

Android GCM multiple push notifications with one icon in status bar

My app wants to bundle multiple push notifications in one icon in the status bar.

When clicking on the icon, the multiple notifications should be received by the app to show them in listview mode.

There are already some entries in stackoverflow which come close to what I want to obtain and it did give me a better insight in handling pending intents and notification flags but they didn´t solve completely my problem.

First step: Creating the notification:

Following some entries in stackoverflow, I made the following assumptions:

The way I see it, each time a notification is sent by GCM, my app generates a notification to send to the notification manager taking into account the previous assumptions.

First problem: if I want to notify the user with the number of pending notifcations left, how can I get track of the previous number of sent notifications? Do I have to store it in storage media?

Second step: Tapping the notification icon in status bar containing multiple notifications:

   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    showNotifications();
   }

   public void onResume() {
    showNotifications();
    super.onResume();
   }


   public void showNotifications() {

   if (getIntent().getExtras() != null) {
    if (getIntent().getExtras().getString("new_message") != null) {
    String newMessage = getIntent().getExtras().getString("new_message");
    if (!newMessage.equals("")) {
           handleMessage(newMessage);
       getIntent().removeExtra("new_message);
    }
    }
   }
   }

   public void onNewIntent(Intent intent) {
   Bundle extras = intent.getExtras();
   if (extras != null) {
         if (intent.getExtras().getString("new_message") != null) {
         String newMessage = intent.getExtras().getString("new_message");
         if (!newMessage.equals("")) {
           intent.removeExtra("new_message");       }
         }
         }
   }
   }

Second problem: I only receive the last notification sent. It seems to be that differentiating the pending intents with requestId didn´t do the trick. Also I thought that the different pending intents related to one notification icon would be handled by onNewIntent... A possible solution that I was thinking about is to save incoming notifications from GCM in storage and get them on tapping the status bar icon, but for sure this cannot be the way Google meant it to be…

¿Any help?

Upvotes: 2

Views: 3647

Answers (1)

ottorottok
ottorottok

Reputation: 191

for second step try this: PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

Upvotes: 1

Related Questions