我对通知没有任何经验,经过很长一段时间后,我感觉真的很蠢,我无法做到:
我从服务器收到推送通知。点击一下,我就会收到
的信息getIntent().getBundleExtra("extra");
在onResume方法中。
但是如果我收到很多通知并且没有在这之间打开我的应用程序,那么如果我点击通知,那我就是最后一个。之前的通知在哪里?最好的是,如果我得到一个捆绑包或类似的东西。我怎么能这样做?
感谢您的帮助,我真的很沮丧:)
编辑:
为了更好地理解:收到GCM后,我会发出如下通知:
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, title, System.currentTimeMillis());
notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
if (extras != null && launchIntent != null) {
launchIntent.putExtra("extra", extras);
}
PendingIntent intent = PendingIntent.getActivity(context, -1, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, title, msg, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(0, notification);
示例:我收到GCM并设置通知。如果我不打开我的应用程序,但获得下一个GCM,那么我的第一个通知将被新的通知替换。这可能是很多次。在几次通知后,我点击它。如果应用程序启动,我将收到已发送的所有通知。目前我刚拿到最后一个。我怎么能得到所有?
答案 0 :(得分:1)
mNotificationManager.notify(0/* 0 is your notification id */, notification);
创建一个id为0的通知。现在,当您收到另一个通知并且使用相同的notificaionId(即0)通知它时。因此,后一个待处理的Intent替换了之前的pendingIntent。 检查docs =>中的notify()说明。 http://developer.android.com/reference/android/app/NotificationManager.html
最好的选择是在某些数据库,首选项或传统方式中本地保存数据 文件以及每当您收到GCM的推送通知时,将其保存在本地,然后通知。