How to customize notification display and tone when using GCMReceiver and GcmListenerService

后端 未结 2 554
北海茫月
北海茫月 2020-12-19 13:56

I have followed instructions to set up an Android GCM client app here, and have a problem specifically with this excerpt:

For existing apps that exten

相关标签:
2条回答
  • 2020-12-19 14:25

    The option that I can only see possible is thru the payload (as you indicated) which are handled by both XMPP and HTTP connection servers. I'm not sure why it seems wrong on your part, since the server will define the sound data in the payload and the client will just need the file present on the respective asset folder it should be.

    Display customization can also be done thru the notification payload (though its limited to color and icon)

    0 讨论(0)
  • 2020-12-19 14:28

    @SamStern answered this question for me, when I posted it on a Google Samples github wiki:

    So there are two kinds of GCM messages:

    Notification Messages - these are intended to generate a notification with no intermediate processing by the application. They only hit onMessageReceived if the app is running.

    Data Messages - these are intended to silently pass data to the app's messaging service. They hit onMessageReceived even if the app is in the background. The service may then choose to generate a notification using the normal system notification APIs, or it may choose to handle the message silently.

    My takeaway is that if a client app wants to customize how a notification is presented to the user (i.e. change the icon in the notification tray, play a sound depending on sound settings in the app's shared preferences, etc), then we have to make the server send "Data Messages" instead of "Notification Messages". Here's the implementation in a Google Samples project, showing how to handle a Data Message.

    0 讨论(0)
提交回复
热议问题