Skip to content Skip to sidebar Skip to footer

How To Get Message From GCM Message Body In Android?

I have an app in which server sends some push notification using GCM server, The implementation is done on both side but i am facing problem is that i can't get notification from m

Solution 1:

Try ,

Bundle notificationData = bundle.getBundle("notification");
String body = notificationData.getString("body");

Solution 2:

It received correct data only

   String bodymessage = bundle.getString("body");

Problem is print message after converting Sting

 Log.e(TAG, "onMessageReceived::" + message.toString());

Solution 3:

You can receive message in onMessage() function of GCMIntentService implementing class. I have created a function for getting proper message and key.

@Override
protected void onMessage(Context context, Intent intent) {
     dumpIntent(intent);
}


public void dumpIntent(Intent i) {

        Bundle bundle = i.getExtras();
        if (bundle != null) {
            Set<String> keys = bundle.keySet();
            Iterator<String> it = keys.iterator();
            while (it.hasNext()) {
                String key = it.next();
                Log.e("Intent Data", "[" + key + "=" + bundle.get(key) + "]");
            }

        }
    }

After that you will easily set message with NotificationManager.


Post a Comment for "How To Get Message From GCM Message Body In Android?"