Open jmrvm801 opened 6 years ago
When creating the channel, set “sound” not “soundname”. https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/API.md#pushnotificationcreatechannelsuccesshandler-failurehandler-channel
That's right. thank you. I'd read about that the soundname and some was equal on Firebase and I though that it was the same case.
@jmrvm801 you are not the first person to make that mistake. I should make it so either label works.
Hi OP, How did you added the mp3 to the Android Project?
I have prblems adding it. I sent the sound name from GCM and I received the soundname in app, but It plays only the phone default notification.
I spent ages trying to solve this, so in the hope that this helps others, I will summarise how I got this to work:
Note: I use the PhoneGap Build cloud service for creation of my APKs and IPAs.
I added these lines to my config.xml that seemed to make the difference:
<platform name="android">
...
<resource-file src="resources/common/sounds/mysound.mp3" target="res/raw/mysound.mp3" />
...
</platform>
<preference name="android-build-tool" value="gradle" />
<plugin name="phonegap-plugin-push" source="npm" spec="2.0.0">
<param name="SENDER_ID" value="12345678" />
</plugin>
...
The resources/common/sounds/mysound.mp3
refers to my local ZIP file structure, and the res/raw/
destination directory for the file. The below screenshot makes this clearer:
If you then open your built APK in a ZIP reader you should see your sound file(s) under the res/raw/
directory in the APK file. This means your sounds are now accessible to your native app container, and the rest depends on the messages you send from FCM.
_Side note: Obviously the SENDERID value has to be changed from 12345678 to whatever Google gives you.
This is my config.xml for Android. iOS needs caf files:
`
`
This is for iOS
`
<resource-file src="notificacion.caf" />
<resource-file src="simulacro.caf" />
<resource-file src="sismo.caf" />
</platform>`
This is my Cordova version:
`
`
My file's structure:
project/
project/alert_android.caf
project/notification.caf
project/simulacro.caf
project/sismo.caf
project/www/alert_android.mp3
project/www/notification.mp3
project/www/simulacro,mp3
project/www/sismo.mp3
For Android > 8 I just implemented the following sentences:
PushNotification.createChannel(() => {},() => {},{ id: 'adnsuiteChannel2', description: 'ADNSuite Broadcast Emergency', importance: 5, vibration: true, sound : 'alert_android' }); PushNotification.createChannel(() => {},() => {},{ id: 'adnsuiteChannel3', description: 'ADNSuite Broadcast PRE-Emergency', importance: 5, vibration: true, sound : 'sismo' }); PushNotification.createChannel(() => {},() => {},{ id: 'adnsuiteNotifySound', description: 'ADNSuite Broadcast Notification V2', importance: 5, vibration: true, sound : 'notificacion' }); PushNotification.createChannel(() => {},() => {},{ id: 'adnsuiteSimulacro', description: 'ADNSuite Broadcast Drill', importance: 5, vibration: true, sound : 'simulacro' });
Expected Behaviour
In Android < 8 the custom sound is played normally
Actual Behaviour
In Android >= 8 instead of play the custom sound is play the default one.
Reproduce Scenario (including but not limited to)
//To Android 8 Channels
Steps to Reproduce
Send a FCM like this:
Platform and Version (eg. Android 5.0 or iOS 9.2.1)
Android 8.0 Android 7.1.1
(Android) What device vendor (e.g. Samsung, HTC, Sony...)
Sony Xperia Z5 (Android 7.1.1) Sony Xperia XZ2 (Android 8.0)
Cordova CLI version and cordova platform version
Plugin version
Sample Push Data Payload
Sample Code that illustrates the problem
Logs taken while reproducing problem
No log was recorded.