1

我使用 GCM(Google Cloud Message)进行推送通知。

当通知到达设备时,它看起来像这样:

Received: Bundle[{message=hello, android.support.content.wakelockid=2,
collapse_key=do_not_collapse, from=243316392621}]

现在我想以只有消息显示在通知上的方式提取消息和wakelockId。(在这个例子中只有你好)

这里我的 notificationBuider 如下:

  NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
    .setSmallIcon(com.example.example.R.drawable.icon)
    .setContentTitle("Example")
    .setDefaults(Notification.DEFAULT_ALL)     
    .setAutoCancel(true)
    .setStyle(new NotificationCompat.BigTextStyle()
    .bigText(msg))
    .setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

请在这方面指导我。任何帮助将不胜感激。

4

2 回答 2

0

根据您收到的通知,我假设它msg是类型Bundle,它的值是GCM BroadcastReceiver 的intent.getExtras()位置。intentintent

您应该从中提取相关参数:

 String text = msg.getString ("message");
 NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
    .setSmallIcon(com.example.example.R.drawable.icon)
    .setContentTitle("Example")
    .setDefaults(Notification.DEFAULT_ALL)     
    .setAutoCancel(true)
    .setStyle(new NotificationCompat.BigTextStyle()
    .bigText(text))
    .setContentText(text);

 mBuilder.setContentIntent(contentIntent);
 mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
于 2014-01-22T20:28:36.853 回答
0

Recibido:捆绑 [{mensaje = hola,android.support.content.wakelockid = 2,collapse_key = do_not_collapse,desde = 243316392621}]

通过这种方式,谷歌发送您在应用程序服务器中定义的数据,您必须做的是单独读取这些数据,例如

extras.getString ("消息")

其中 message 是定义了服务器应用程序键值的数据

于 2015-04-11T07:25:46.550 回答