question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Local Notification channel creation not working

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Maraaghibcommented, Dec 15, 2020

@MInesGomes I have fixed this issue by creating first a channel:

image The ‘slap.wav’ file is stored in android\app\src\main\res\raw\ folder

Then, I schedule my notification without speciying the sound path:

image

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

0reactions
ionitron-bot[bot]commented, Nov 11, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flutter Local Notifications Plugin: createNotificationChannel ...
I am trying to create an android notification channel with flutter_local_notifications: ^5.0.0+4 Put it looks like it does not work as ...
Read more >
Create and Manage Notification Channels - Android Developers
Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel. For each channel, you can set the visual...
Read more >
Manage notification channels by API | Cloud Monitoring
This document describes how to create and manage notification channels by using client libraries or by using the Google Cloud CLI, both of...
Read more >
Unity Mobile Notifications Package | 1.1.0-preview
Create a notification channel. Every local notification must belong to a notification channel. ... Error; res += "\n deviceToken: " + req.
Read more >
Notifications - Laravel - The PHP Framework For Web Artisans
You may use $notifiable to determine which channels the notification ... When using the error method on a mail message, the call to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found