Here is my interesting problem. Android notification that comes from GCM is not showing title and content (just shows App Name, and when click, open the Mai
In brief: try setting content_available=false
when building the push on server side. The explanation follows.
This happens from version 8.4.0 of play services.
The documentation says that if you send a downstream message with both data
and notification
payload, the behavior changes if the App is in foreground or in background:
onMessageReceived
is called and you can manually handle your notificationtitle
and body
from the notification payload. If you don't specify them, the title
is filled with application name and the body
is left empty (and that's seems your case).In your case I saw, in the message bundle, this strange thing notification=Bundle[{e=1}]
I encountered the same problem. This notification payload is self generated. I managed to remove it by setting content_available=false
when building the push on server side. This is a problem if you are also working with iOS, but I didn't find any better solution...try it out.
Here the google doc I cited: https://developers.google.com/cloud-messaging/concept-options#notifications_and_data_messages
Hope it helps, bye
Instead of
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
try using
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(0, mBuilder.build());
Lollipop changes this slightly by creating a small pop up at the top of the device window when a Notification is created.
Here's a Official documentation: setFullScreenIntent
Using this method, you can create a new Activity with any custom layout you want and launch that instead of placing the Notification in the status bar.
Found the problem. I was using 8.4.0 version (up-to-date) of play services.
compile 'com.google.android.gms:play-services-gcm:8.4.0' //GCM
I reduced the version to 8.3.0
. It works as expected.
The problem is with the GCM 8.4.0 version, it is sending a notification payload even if you don't send it in your server.
notification=Bundle[{e=1}
But if you add this e
field with value zero
in your server it will work.
For more details se my answer here.
I think your issue is in this line:
you have not included this:
<service
android:name="com.example.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>