我已经实现了GCMIntentService,每当我得到推送通知时我都需要显示 通知菜单中的通知并打开包含一些包值的活动 意图。 我可以在通知菜单中看到通知,但点击它只是没有做任何事情。以下是我正在使用的代码: -
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent i = new Intent(this, ChatDetail.class);
Bundle b = new Bundle();
b.putString("my_id", "5356b178b130a74a57019fe9");
b.putString("you_id", youId);
i.putExtras(b);
// PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
// new Intent(this, MainActivity.class), 0);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
i,PendingIntent.FLAG_CANCEL_CURRENT );
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.pool_my_ride_icon)
.setContentTitle("GCM Notification")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(text))
.setContentText(text);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
我可以看到通知,但是当我点击它时,通知菜单会向上滑动而不是 做任何事都不会打开任何活动。 如果我不在附加内容中发送任何捆绑,那么我可以打开活动但是当我发送时 捆绑值然后我无法打开活动。
提前致谢
答案 0 :(得分:0)
我会尝试一次添加额外的意图:
i.putExtra("my_id", "5356b178b130a74a57019fe9");
i.putExtra("you_id", youId);
答案 1 :(得分:0)
Intent i = new Intent(this, ChatDetail.class);
Bundle b = new Bundle();
b.putString("my_id", "5356b178b130a74a57019fe9");
b.putString("you_id", youId);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
i.putExtras(b);
这里重要的一点是发送额外的标志以实际上希望你的意图被传递
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
请告诉我它是否适合您!