【发布时间】:2014-05-28 11:06:26
【问题描述】:
我正在为我的 android 应用程序使用 Google 云消息传递。GCM 部分运行成功。现在我想在用户点击状态栏中的通知图标时在 UI 活动中显示消息。
我正在使用以下代码从通知中启动我的 ResultShowActivity。
Intent notificationIntent = new Intent(context, ResultShowActivity.class);
notificationIntent.putExtra("Message",msg);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.gcm_cloud)
.setContentTitle("GCM Notification")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setAutoCancel(true)
.setSound(alarmSound)
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
消息正在正确发送,并在 GCM 通知出现时正确显示,但是当我在 ResultShowActivity 中捕获额外的意图时,它总是显示旧消息。 我正在使用以下代码从 ResultShowActivity 中的意图接收消息。
String GCMMsg = showViewIntent.getStringExtra("Message");
我尝试使用
删除 ResultShowActivity 中的intent.removeExtra("Message");
或
intent.replaceExtras(extras);
任何人都可以建议如何从意图中检索更新的消息。感谢您对此提供的任何帮助。
【问题讨论】:
标签: android android-intent push-notification