bug: Local Notification channel creation not working
See original GitHub issueBug Report
Capacitor Version
Latest Dependencies:
@capacitor/cli: 2.4.0
@capacitor/core: 2.4.0
@capacitor/android: 2.4.0
@capacitor/electron: 2.4.0
@capacitor/ios: 2.4.0
Installed Dependencies:
@capacitor/ios not installed
@capacitor/cli 2.4.0
@capacitor/android 2.4.0
@capacitor/core 2.4.0
@capacitor/electron not installed
[success] Android looking great! 👌
Platform(s)
Current Behavior
Sound only works if I define in capacitor.config.json. Doesn’t work if I want to create a dynamic channel sound (for api 26+) And it doesn’t play custom sound for api < 26
Expected Behavior
I have a working app with cordova where I can set dynamically the sound I just need to set a name for the channel and the sound and plays custom sound For api 26+ uses the channel & sound, for api < 26 uses just the sound
It would be nice to have something similar Cordova code is here: https://github.com/Steffaan/cordova-plugin-local-notifications/blob/06863a7b453706a1335119ac7cdd7cc157f765de/src/android/notification/Manager.java#L120
Code Reproduction
capacitor.config.json
bebep.mp3 is working
"LocalNotifications": {
"smallIcon": "ic_stat_icon_config_sample",
"iconColor": "#488AFF",
"sound": "bebep.mp3"
}
home.ts
const channel: NotificationChannel = {
id: '12',
name: 'channel1',
importance: 5,
sound: 'emergency.mp3'
};
Plugins.LocalNotifications.createChannel(channel); // <- give an error if api < 26
LocalNotifications.schedule({
notifications: [{
title: 'Test',
body: 'testing sound',
id: 1,
channelId: '12' // <- If I comment works the default sound set in capacitor.config.json
}]
});
If I print the list of channels it gives me this:
Array(2)
0:
description: ""
id: "12"
importance: 5
lightColor: "#000000"
lights: false
name: "channel1"
sound: "android.resource://io.ionic.starter/raw/emergency"
vibration: false
visibility: -1000
1:
description: "Default"
id: "default"
importance: 3
lightColor: "#000000"
lights: false
name: "Default"
sound: "android.resource://io.ionic.starter/2131623936"
vibration: false
visibility: -1000
this
sound: "android.resource://io.ionic.starter/raw/emergency"
doesn’t have an extension
Other Technical Details
npm -v. 6.14.5 node -v. v12.18.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
@MInesGomes I have fixed this issue by creating first a channel:
The ‘slap.wav’ file is stored in
android\app\src\main\res\raw\
folderThen, I schedule my notification without speciying the sound path:
PS: I did not do any configuration on capcitor.config.json
It works perfectly on Samsung Galaxy A71 (SM-A715F) - Android 10
If you want to change dynamically the notification sound, you delete this channel and create another one with only a different id
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.