繁体   English   中英

适用于adf移动版的Android推送通知:消息为空白

[英]Android push notification for adf mobile: Message is coming blank

我们正在尝试为adf mobile实施推送通知。 我们按照以下两个博客进行了实现, 网址http://deepakcs.blogspot.in/2013/06/adf-mobile-push-notifications-with.html

对于服务器端,我们引用了此处的信息http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/

我们在收到来自GCM的通知消息时遇到问题。 当我们从提供商应用程序发送通知时,我们会收到带有警报声音和客户端应用程序名称的通知,但消息为空白或null。

我们的onMessage()方法(当推送通知到达客户端应用程序时将调用的方法如下)

public void onMessage(Event event) {
    //Parsing the payload JSON string
    JSONBeanSerializationHelper jsonHelper = new JSONBeanSerializationHelper();
    try {
        PayloadServiceResponse serviceResponse =
            (PayloadServiceResponse)jsonHelper.fromJSON(PayloadServiceResponse.class, event.getPayload());
                    Map session = (Map)AdfmfJavaUtilities.evaluateELExpression("#{applicationScope}");

        String newMsg = serviceResponse.getCustomMessage();
        session.put("pNewMessage", newMsg);
    } catch (Exception e) {
        e.printStackTrace();

    }

我们试图将接收到的消息存储在应用程序范围内,以便在用户点击通知时显示在我们的UI页面中(当用户点击通知消息时,它将带他到此页面并需要显示通知消息),但是有些方法我们收到空白消息。 每当我们从提供商方发送通知时,只有通知警报声音和客户端应用名称出现。

有人可以建议吗?

谢谢。

我在使用GCM时遇到了同样的问题。 收到通知,但某些设备中的消息为空白。

我可以通过在NotificationCompat.Builder上添加以下行来解决此问题:

.setContentTitle(appName)
.setContentText(message)

这是最终代码:

NotificationCompat.Builder nBuilder;
    nBuilder = new NotificationCompat.Builder(context)
        .setDefaults(Notification.DEFAULT_ALL)
        .setSmallIcon(smallIcon)
        .setWhen(System.currentTimeMillis())
        .setAutoCancel(true)
        .setContentTitle(appName)
        .setContentText(message)
        .setTicker(message)
        .setVibrate(new long[] { 100, 250, 100, 250, 100, 250 })
        .setSound(alarmSound)
        .setPriority(Notification.PRIORITY_MAX);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM