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 extend a WakefulBroadcastReceiver, Google
recommends migrating to GCMReceiver and GcmListenerService. To
migrate: In the app manifest, replace your GcmBroadcastReceiver with
"com.google.android.gms.gcm.GcmReceiver", and replace the current
service declaration that extends IntentService to the new
GcmListenerService Remove the BroadcastReceiver implementation from
your client code Refactor the current IntentService service
implementation to use GcmListenerService
Most examples that I have seen for GCM implementation, use a class that extends WakefulBroadcastReceiver
. Such as this one. When you do that, you get the opportunity to use the NotificationManager
and customize the notification icon, sound, etc. However, if you follow Google's advice, I'm not sure how to customize the notifications. Most examples that use GcmListenerService
as suggested by Google, simply override the onMessageReceived
method. But that method is only called either if the application is already in the foreground when the notification is received, or when the user clicks on the notification itself. That method isn't the right place to customize the notification sound. The sound has already been played before that method is called.
So, if I need to customize the notification sound, I should probably override a different method in GcmListenerService
, but there's no documentation that shows which one. Another option is to use the sound
attribute described here. But then you have to bundle the sound files in the application's res/raw
directory yourself. That seems wrong. I'd rather just use the system provided sounds, themes, etc.
Thoughts?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…