Android notification is not showing it's content when app is not running

后端 未结 6 1045
孤街浪徒
孤街浪徒 2020-12-28 15:49

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

6条回答
  •  再見小時候
    2020-12-28 15:59

    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:

    • in foreground the listener onMessageReceived is called and you can manually handle your notification
    • in background the notification is automatically built by the system by taking title 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

提交回复
热议问题