【发布时间】:2013-11-24 13:37:26
【问题描述】:
我正在尝试使用 GCM 开发推送通知服务。我能够接收从服务器发送到我的设备的通知。单击通知后,应用程序将打开。好的。现在我想要的是通知上的消息也应该显示在应用程序上。我该怎么做?
Code in GCMintentservice.java:
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_action_search_)
.setContentTitle("GCM Notification")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
现在我收到了通知,但点击通知后,我进入了应用程序,但消息不存在。我该怎么办。我在主应用程序中有一个文本视图。如何使用通知中的消息更新该文本视图?可能在主应用程序中的 OnCreate 上做些什么?请帮忙。
问候
【问题讨论】:
标签: android android-intent notifications push-notification google-cloud-messaging