【问题标题】:How to extract data from Message and display it in Notification(Android)如何从 Message 中提取数据并在 Notification(Android) 中显示
【发布时间】:2013-09-23 12:07:30
【问题描述】:

我使用 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());

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

【问题讨论】:

    标签: notifications push-notification google-cloud-messaging android-notifications


    【解决方案1】:

    根据您收到的通知,我假设msg 的类型为Bundle,其值为intent.getExtras(),其中intent 是GCM BroadcastReceiver 的intent

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

     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());
    

    【讨论】:

      【解决方案2】:

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

      Google 以这种方式发送您在应用程序服务器中定义的数据,您必须单独读取这些数据,例如

      extras.getString(“消息”)

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

      【讨论】:

        猜你喜欢
        • 2016-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多