我正在使用GCM服务,在收到消息后,我制作了Notification
。如果我收到通知,然后使用多任务面板关闭应用程序,然后单击通知,它会正确启动应用程序,但之后如果我收到另一个通知并单击它,则没有任何反应。
这是代码,它发出我的通知。它在我的服务中,扩展了GcmListenerService
。
Intent mainActivityIntent = MainActivity_.intent(this)
.extra("url",gcmMessage.getUrl())
.get();
mainActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, mainActivityIntent,
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.streamy_logo_notification)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.streamy_logo))
.setContentTitle(getString(R.string.notification_title))
.setContentText(gcmMessage.getMessage())
.setContentIntent(contentIntent);
Notification notification = builder.build();
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(9999, notification);