Matt6097125
Posts: 0
Joined: Tue Jul 30, 2013 6:56 pm

Vibrate/Sound on Push Notification

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Vibrate/Sound on Push Notification

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

Matt6097125
Posts: 0
Joined: Tue Jul 30, 2013 6:56 pm

Vibrate/Sound on Push Notification

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?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Vibrate/Sound on Push Notification

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.

Matt6097125
Posts: 0
Joined: Tue Jul 30, 2013 6:56 pm

Vibrate/Sound on Push Notification

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Vibrate/Sound on Push Notification

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

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

Matt6097125
Posts: 0
Joined: Tue Jul 30, 2013 6:56 pm

Vibrate/Sound on Push Notification

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.

Matt6097125
Posts: 0
Joined: Tue Jul 30, 2013 6:56 pm

Vibrate/Sound on Push Notification

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?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Vibrate/Sound on Push Notification

That's Google Cloud Messaging Java file.

Return to “Issues”