0

I have an Android app with a working push notification set up. It works currently like this:

  1. User gets a push notification
  2. When the user taps on the push notification, he is taken to a screen which has the list of all the notifications. It is basically a list view which has all the notifications.

Now, want to implement the following:

a. When a new notification comes to the user, it has to be displayed on the list view, irrespective of whether a user taps on it.

b. I have to indicate the number of notifications that user has received on the app icon. For instance, if you get a message in whats app, it displays the number of messages on the app icon.

Could anybody let me know what is the best possible way to implement these functionality? If anybody could point me to tutorials/references, it would be very helpful.

Thanks!

Var
  • 199
  • 2
  • 13

1 Answers1

0

a. Launch an activity from the receiver(GCM/C2DM receiver) when the push notification arrives

    // Your C2DM receiver (for GCM check the Android Documentation)
    public void onReceive(final Context context, final Intent intent)
    {
            if (intent.getAction().equals(com.google.android.c2dm.intent.RECEIVE))
            {
               //start your list view activity of notifications
               Intent i = new Intent();
               i.setClassName("com.test", "com.test.NotificationsActivity");
               i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
               context.startActivity(i);
            }
    }

b. Check this.

Community
  • 1
  • 1
AK42
  • 831
  • 7
  • 12
  • Thank you for the reply. Could you please give me an example of to implement part a? I did not really understand the solution that you have posted. – Var Nov 20 '14 at 07:20
  • ,Thank you for the answer! – Var Nov 20 '14 at 09:14