-
Notifications
You must be signed in to change notification settings - Fork 985
Support for custom sounds on Android #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Is it not possible to have the sound relative to www? Ideally users should not have to update files within the platforms directory. |
I agree, yet I found myself having to modify contents of Regardless, I would prefer to use a resource under |
Hey. Any news? I'ms very interested by the possibility to put the soundfile in the www folder |
Playing a file that is located in the The "normal" way to supply a custom notification sound is to provide one that resides in the resources of your package, which is what this change implements and which is what we're using. I guess you could write the asset from your package to another location and then provide a Uri to that location to have a custom sound from your assets play. But that didn't seem like it was worth the effort. |
OK thanks I understand |
@alexislg2 Could you point me towards the relevant documentation sections regarding this? |
I'm sorry I made a mistake. It's just in my own JS code for handling payload while in foreground So please don't consider my last comment! |
BTW I had to remove the |
@alexislg2 Where did you remove it from? PushPlugin sets the defaults according to the |
From here ! The best way to do that would be to use DEFAULT_SOUND if no payload sound has been provided or if no ressource corresponds, otherwise use the payload sound |
Ah, yeah, I see it now. We specifically set |
I tried this PR with PushPlugin/1979d972 and cordova 3.6.3-0.2.13, on Nexus S with 4.2.1 OS, using the codes from PushPlugin/Example, with following changes:
What I got is with or without the patch: I tried copy the beep.wav to platform/res/raw/beep.wav, but it didn't help. I also tried change the defaults from Notification.DEFAULT_ALL to zero in GCMIntentService.java, it just mutes the sound when the app is in background. When the app is in foreground, I got the same sound of beep.wav. And I tried changing "beep.wav" to "beep" in pushGCM.rb, it will then mute the sound when the app is in foreground. So it seems this patch doesn't change anything to me, or I did something wrong? |
@lyonplus I can assure you that the patch has an effect as we're using it successfully in production. I've never used any of the examples, so I can't tell you where the problem with those might be. You definitely must not set |
@oliversalzburg Thanks for confirm. Could you please tell me what is the difference you see in your environment? Like before your patch it is always the default alert sound and with your patch it is your custom sound, both foreground and background? |
@lyonplus When we're in the foreground, we don't get any sound, because no notification is created. This is the default behavior of PushPlugin. (for reference) Our patch allows you to specify a custom sound. And that sound will be played whenever PushPlugin would play a sound. |
If you want foreground notifications you have to use the Media plugin to
|
@oliversalzburg: With patch like below, I am now able to get the custom notification sound for both foreground and background. diff --git a/src/android/com/plugin/gcm/GCMIntentService.java b/src/android/com/plugin/gcm/
|
@lyonplus That change isn't necessary. You can already adjust the |
@oliversalzburg what i'm wrong? |
|
Hi, |
@zbranzov You don't have to remove the line, just supply |
@oliversalzburg Thanks for this patch! I've has success using it in my project. One thing though, have you ever experienced the default notification sound playing alongside the custom sound? I set defaults to 0, and sometimes the notifications come in with just the custom sound, other times both sounds play. Looking at logcat it seems like the notification is being received multiple times... |
@bostondv No, we're not experiencing that. We're using custom notification sounds exclusively and we never get the default sound additionally. Maybe try not setting a sound at all, and see if the default sound still appears. It might be another part of the application causing the sound. |
Thanks, have tried that actually. I'm able to get sound to go away entirely
|
Sorry, but the solution of @oliversalzburg don't work for me...
A simple question: in the createNotification function no one makes the call to setSound of mBuilder (http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html) This may be the error? |
Hi, what's the status of this? Why isn't it merged? I placed the notification sounds in |
@miparnisari For Android you need to create a folder inside platform/android/res/ directory and called it "raw" and put there the sound file, the audio file must be .wav, and in Ionic.io json: {"badge" => 1, "sound" => "savvynotification"} notice that it doesn't need the extension name. |
Why wav? I saved it as mp3 and it works on my android. Is it for older Also, I'm already sending the "badge" property (through node-gcm) but it -- Maria Ines
|
To make use of this, the sound must be placed in the platforms/android/res/raw folder and must be of one of the supported media types (http://developer.android.com/guide/appendix/media-formats.html).
In the push notification payload, specify the sound without the file extension. If your file is named "platforms/android/res/raw/alert.mp3", use "alert" as the name.