Page 1 of 1

Vibrate/Sound on Push Notification

Posted: Fri Dec 06, 2013 10:49 pm
by Matt6097125

Hi There -

I'm trying to get vibration and sound to happen when a push is received for my android app. I have the pushes working correctly. I'm just not sure how to activate sound/vibrate. It looks like there may be some javascript I can put in the app (navigator.notification.beep(2);), but that wasn't successful. Ultimately, I'd like this attached to the push itself so that app doesn't need to be open to make the sound/vibrate work.

Any tips? I'm sure I'm just missing it somewhere...

Thanks for the help.
-Matt


Vibrate/Sound on Push Notification

Posted: Fri Dec 06, 2013 10:58 pm
by maxkatz

Use "push notification" event to run the PhoneGap vibrate code that you have above.


Vibrate/Sound on Push Notification

Posted: Fri Dec 06, 2013 11:09 pm
by Matt6097125

Thanks for the quick reply Max.

I tried that and it doesn't seem to be working. As a test, I put that javascript on a Device ready event to try and eliminate anything with the push -- it's still not working.

I have "VIBRATE" permissions selected for Android. Are there any other permissions I would need to make it go?


Vibrate/Sound on Push Notification

Posted: Fri Dec 06, 2013 11:18 pm
by maxkatz

Are you testing on the actual device?

You should use "Push notification" event and just try to do a simple alert(..) to make sure that works.


Vibrate/Sound on Push Notification

Posted: Fri Dec 06, 2013 11:22 pm
by Matt6097125

Hi Max,

Yeah, I'm on the actual device. I did an alert just to make sure the JS was firing when Push notification came in and that works fine. That app also redirects to the page when the Push notification is fired. So, it doesn't seem to be with that event.

Rather, it seems to be with the navigator javascript itself. I also ran this recommended test script and it didn't do it either:

precode
document.addEventListener("deviceready", function(){
navigator.notification.vibrate(1000);
navigator.notification.alert("Hello");
navigator.notification.beep(1);
}, false);
/code/pre


Vibrate/Sound on Push Notification

Posted: Sat Dec 07, 2013 12:01 am
by maxkatz

I thought you wanted to run this when a push notification is received:

code
navigator.notification.vibrate(1000);
/code


Vibrate/Sound on Push Notification

Posted: Mon Dec 09, 2013 9:59 pm
by Matt6097125

Hi Max -

So, I've played with this over the weekend a bit more. I now have the push notifications triggering a sound without the need for additional JS within the app. However, I still can't get the vibrate to work right.

When I put the vibrate JS within the Push Notification event, everything pretty much worked. When I got notified, the tablet vibrated. However, when I clicked on the push notification to enter the app, the sound/vibration would fire again when it hit the Push Notification event within the app.

Removing the JS from the push notification gave me the desired functionality of just the sound happening just on the initial push notification, but vibrate isn't working. When installing the app, I can confirm it's asking for vibration rights - so at least I have the permissions right.

Can you think of any reason why a push notification would only fire the sound and not fire the vibration?

Thanks again.


Vibrate/Sound on Push Notification

Posted: Mon Dec 09, 2013 10:20 pm
by Matt6097125

I've traced the source code back to the function "generateNotification" in /src/com/XXXX/app/GCMIntentService.java (line 88).

This function seems to be where the notifications are send to the OS. I'm not seeing anything in this function relating to vibrating.

Is this file generated by Appery.io? If so, should I be adding the vibration command here?


Vibrate/Sound on Push Notification

Posted: Mon Dec 09, 2013 11:31 pm
by maxkatz

That's Google Cloud Messaging Java file.