简体   繁体   中英

Android push notification for adf mobile: Message is coming blank

We are trying to implement push notification for adf mobile. we followed these two below blogs for our implementation http://deepakcs.blogspot.in/2013/06/adf-mobile-push-notifications-with.html

and for server side we have refered information present here http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/

we are facing issue while receiving notification message from GCM. When we send notification from our provider application we receive notification with alert sound and client app name but message coming as blank or null .

our onMessage() method(this is the method which will invoke when push notification arrives in client app is as follows)

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

    }

we are trying to store the received message in application scope in order to display in our UI page once the user tapped the notification(when user tapped the notification message it will take him to this page and needs to show the notification message) but some how we are receiving blank message. only notification alert sound and client app name is coming whenever we send a notification from provider side.

could any one suggest on this?

thank you.

I was facing the same problem working with GCM. The notification was received, but the messages were blank in some devices.

I was able to fix it by adding this lines on my NotificationCompat.Builder :

.setContentTitle(appName)
.setContentText(message)

This is the final code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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