GCM notification not showing

I'm trying to use a feature where android automatically displays notifications when push messages are received as described here
Not only does the notification seem to not be duplicated, but onMessageReceived

not triggered at all when I add a field notification

to my JSON payload. Everything will be fine without this field.
Here's my json payload:

{
 "to":"APA91bGIe59H1V5SsQkKvDOTgCTEaZWwgCJrdQ...",
 "message_id":"",
 "notification":{
                 "body":"Notification test",
                 "title":"Notification header",
                 "icon":"noti.png"
                },
 "data":{
         "test_message":"GCM test message!"
        }
}

      

So why is this happening? Or are there no automatic notifications? (What is the field notification

, if so ... I can use the field data

if I have to create notifications myself)

Edit: He
finally got it to work. The icon field should be like "icon":"@drawable/noti"


Google documentation errors are really annoying.

+3


source to share


1 answer


In my case, the notification was not displayed because I did not set the notification element when creating the notification. This builder worked:



NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_ic_notification)
                .setContentTitle("GCM Message")
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

      

0


source







All Articles