Query regarding Android push notifications

风格不统一 提交于 2019-12-25 16:48:21

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/27032306/query-regarding-android-push-notifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!