我有一個應用程序在哪個服務器使用GCM服務器發送一些推送通知,實現在兩端完成,但我面臨的問題是,我無法從消息正文獲取通知,它總是向我顯示「null」。但是我可以使用調試在消息體內看到消息。如何從android中的GCM消息體獲取消息?
String message = bundle.getString("message");
Log.e(TAG, "onMessageReceived::" + message);
Log.e(TAG, "from::" + from);
和消息主體是: -
Bundle[{google.sent_time=1497866966996, google.message_id=0:1497866967011288%466cbbd8466cbbd8, notification=Bundle[{priority=high, body=Your wallet has been credited with 1.000 point(s)., title=Wallet credited}], collapse_key=com.s.baty}]
您必須將您的通知作爲JSON發送。你的身體應該包含這樣的內容{「gcm.notification.title」:「」, 「gcm.notification.body」:「」},你可以得到像這樣的身體bundle.getString(「gcm.notification.body」 ) –