Gcm play sound

41 views
Skip to first unread message

alexand...@hn-websolutions.com

unread,
Mar 30, 2016, 5:34:39 AM3/30/16
to android-gcm
Hello,

I am creating an app with ionic and ngCordova. The app shell receive push notifications.

I have adopted an example from ngCordova.

http://ngcordova.com/docs/plugins/pushNotifications/

My .run method looks like this:

 <code>
  .run(function ($ionicPlatform, $rootScope, User, $cordovaDialogs, $cordovaVibration, $cordovaPush) {
         $ionicPlatform.ready(function () {

                 var androidConfig = {
                     "senderID": "xxx",
                 };

                 $cordovaPush.register(androidConfig).then(function(result) {
                     // Success
                 }, function(err) {
                     // Error
                 })

                 $rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
                     switch(notification.event) {
                         case 'registered':
                             if (notification.regid.length > 0 ) {
                                 console.debug('registration ID');
                                 console.debug(notification.regid);
                             }
                             break;

                         case 'message':
                             // this is the actual push notification. its format depends on the data model from the push server
                             alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
                             break;

                         case 'error':
                             alert('GCM error = ' + notification.msg);
                             break;

                         default:
                             alert('An unknown GCM event has occurred');
                             break;
                     }
                 });
             });
     })
 </code>


I send push notifications with the following script:

https://github.com/mattg888/GCM-PHP-Server-Push-Message

The messages arrive, as far so good.

But I can't manage to play a sound/tone. According to GCM documentation, this should work with the parameter sound and the value default.

My GCM request looks like this:

 <code>
 $apiKey = "YOUR GOOGLE API SERVER KEY";
 $devices = array('YOUR REGISTERED DEVICE ID');
 $message = "The message to send";

 $gcpm = new GCMPushMessage($apiKey);
 $gcpm->setDevices($devices);
 $response = $gcpm->send($message, array('title' => 'Test title', 'sound' => 'default'));
 </code>


Has someone an idea why the sound is not played?

Thank you in advance!

Diego Giorgini

unread,
Apr 28, 2016, 6:00:03 PM4/28/16
to android-gcm
Hi Alexander,

please check that you are using the latest google play services SDK library.

When you write "The messages arrive, as far so good.", do you mean that you are receiving the message in Cordova,
or that you can see the Android notification appearing in the notification tray?

--
You received this message because you are subscribed to the Google Groups "android-gcm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-gcm...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-gcm/824df40c-b7d6-49bf-946a-68307a6d25aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages