-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GcmListenerService.onMessageReceived()
is only called if app is in foreground
#166
Comments
I think the real issue here is that you are only receiving Once you get that working, you can set up some UI like the screenshot above that allows the user to pick from a list of system notification sounds and save the URI of the sound to |
Thanks for the quick reply @samtstern . I'll dig deeper to see why my |
So there are two kinds of GCM messages:
Is it possible that you are sending Notification messages and you want to be sending Data messages? |
Ah got it! I'm indeed sending Notification Messages from my server. Looks like Notification Messages should only be used if all we want to do is display the notification in the notification tray. Then, data will be passed to the app, only once the user clicks on the notification, and there's a |
Yep, that's the correct understanding. I'm going to close this issue now, good luck! |
Sounds good, and thank you for your help. I have referenced this issue in my SO question. |
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 callssendNotification()
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 thatGcmListenerService
is used for "...automatically displaying simple notifications on the app’s behalf." . So why is theNotificationManager
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 theGcmListenerService
(and notonMessageReceived()
) 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'sres/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.
The text was updated successfully, but these errors were encountered: