Skip to content
This repository was archived by the owner on Jul 2, 2025. It is now read-only.
This repository was archived by the owner on Jul 2, 2025. It is now read-only.

GcmListenerService.onMessageReceived() is only called if app is in foreground #166

@sailrish

Description

@sailrish

I can't find a way to customize a notification's sound. Ideally, I want to let my users select one of several system defined ringtones (see attached image below), just like Gmail does.

The onMessageReceived() method calls sendNotification() in order to customize the notification sound, icon, title and message that gets displayed (and the intent tied to it, describing the action to take when user clicks on the notification). However, this article suggests that GcmListenerService is used for "...automatically displaying simple notifications on the app’s behalf." . So why is the NotificationManager being used at all in this sample code?

In practice, I have noticed that onMessageReceived() is only called if the application is in foreground, when a push notification is received. And if the application is not running, something else in the GcmListenerService (and not onMessageReceived()) is responsible for displaying the notification to the user. Is this true? If so, it appears that there is no way to customize the formatting of the notification, if the application isn't running. For example, if I want to change the sound and icon of the displayed notification, the only way to do so is by specifying the appropriate attributes in the GCM payload described here. That's all fine and dandy, but it poses another challenge. What if I want to specify a sound to be played that is one of the system defined sounds (see image below)? The only way to do that is to bundle all these system sounds in my app's res/raw folder. But that seems silly. Every app will have to bundle the same set of sounds (shown in the image below) to accomplish this. What am I missing? It seems GCM is trying to be the "least common denominator" in order to interoperate with iOS devices. iOS does not allow customization of notification sounds, except if the app itself provides the sound files in its resource bundle. And GCM is going the same way with Android.

See my stackoverflow question here.

image

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions