Having a difficult time getting a push notification to play a sound. The documentation (https://docs.coronalabs.com/guide/events/appNotification/index.html#notification-sounds) seems to imply that if you include a sound file name in the push notification that the system will play it. I’ve tried every permutation of that in the gcm notification and nothing changes on the notification receipt. Any insight into how to get a different sound to play on notification receipt?
Have a look at sample project “System/GooglePushNotifications” that is included with the Corona Simulator.
That sample project plays a *.wav file when a notification has been received.
In particular, the “main.lua” file’s onTap() function. It shows you how to set up the JSON message. It’s pretty well commented.
Is there something special corona is doing with respect to the sound setting? The “data” field specified in gcm seems to have no meaning to google, so I assume the corona runtime has setup to handle the notification and not play the sound based on the setting in the notification?
You have to remember that Google’s GCM service is just a messaging service. It doesn’t actually post notifications to the status bar like how Apple’s remote notifications work. It only sends a JSON packet to an app and that’s it. It’s up to the app to decide what to do with the received message. So, extra information needs to be embedded into the JSON table to tell the app what to do with the message.
So, back to your question, the “data” section of the JSON table is defined by Corona Labs which tells our software how to display/handle the received message as a notification in the status bar. Such as “alert” for the message, “sound” for which sound file asset to play, and “custom” which is an optional table you can tack on to identify the notification and provide extra information. The entries under the “data” table matches what you would send in an iOS notification. So, if you reference a sound file as shown in that sample project, then Corona will play that sound when the notification has been received. Otherwise, the Android OS will play its default sound and this may vary depending on OS version or various Android OS forks.
I recommend that you try out our GooglePushNotification sample project first. It does a good job showing you the various things you can do with notifications on Android. That sample app is able to push a notification to itself. You just have to add your “projectNumber” to the “config.lua” file and your “googleApiKey” to the top of the “main.lua” file, and then you’re good to go.
I did try the app after you indicated it was there (thanks for that), then wrote my own push server function based on the sample app and tested it and got it working which is why I was wondering how the sound setting worked since googles documentation made no reference to a sound setting (except in the new notification setting but indicating it only supported default). Thus my question on whether corona was doing something specific there. I assume that the notification field is something that corona would also have to handle? It might be helpful if it was more clearly stated that the “data” fields are defined by corona labs (I’m not sure that’s mentioned in the documentation anywhere) and list all of the ones that are available. This might also be a good place to add the vibrate option several people were requesting in the forums.
Thanks for the assistance
Right. My point was that GCM doesn’t support pushing notification to the status bar. It has no support for status bar notifications at all. No sound. No text. It merely delivers a JSON packet. That’s why you can’t find any documentation on Google’s end. And every 3rd party push notification system on Android does their own thing because of this.
Anyways, I’m glad you got it working.
Have a look at sample project “System/GooglePushNotifications” that is included with the Corona Simulator.
That sample project plays a *.wav file when a notification has been received.
In particular, the “main.lua” file’s onTap() function. It shows you how to set up the JSON message. It’s pretty well commented.
Is there something special corona is doing with respect to the sound setting? The “data” field specified in gcm seems to have no meaning to google, so I assume the corona runtime has setup to handle the notification and not play the sound based on the setting in the notification?
You have to remember that Google’s GCM service is just a messaging service. It doesn’t actually post notifications to the status bar like how Apple’s remote notifications work. It only sends a JSON packet to an app and that’s it. It’s up to the app to decide what to do with the received message. So, extra information needs to be embedded into the JSON table to tell the app what to do with the message.
So, back to your question, the “data” section of the JSON table is defined by Corona Labs which tells our software how to display/handle the received message as a notification in the status bar. Such as “alert” for the message, “sound” for which sound file asset to play, and “custom” which is an optional table you can tack on to identify the notification and provide extra information. The entries under the “data” table matches what you would send in an iOS notification. So, if you reference a sound file as shown in that sample project, then Corona will play that sound when the notification has been received. Otherwise, the Android OS will play its default sound and this may vary depending on OS version or various Android OS forks.
I recommend that you try out our GooglePushNotification sample project first. It does a good job showing you the various things you can do with notifications on Android. That sample app is able to push a notification to itself. You just have to add your “projectNumber” to the “config.lua” file and your “googleApiKey” to the top of the “main.lua” file, and then you’re good to go.
I did try the app after you indicated it was there (thanks for that), then wrote my own push server function based on the sample app and tested it and got it working which is why I was wondering how the sound setting worked since googles documentation made no reference to a sound setting (except in the new notification setting but indicating it only supported default). Thus my question on whether corona was doing something specific there. I assume that the notification field is something that corona would also have to handle? It might be helpful if it was more clearly stated that the “data” fields are defined by corona labs (I’m not sure that’s mentioned in the documentation anywhere) and list all of the ones that are available. This might also be a good place to add the vibrate option several people were requesting in the forums.
Thanks for the assistance
Right. My point was that GCM doesn’t support pushing notification to the status bar. It has no support for status bar notifications at all. No sound. No text. It merely delivers a JSON packet. That’s why you can’t find any documentation on Google’s end. And every 3rd party push notification system on Android does their own thing because of this.
Anyways, I’m glad you got it working.