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.

Local notification sounds

See original GitHub issue

I’ve looked at the current documentation for local notification, and while it does display which methods and options are available, it does not explain what type can be used for each option. What I’m trying to do is use a custom notification sound, but I haven’t got it working yet. The sound is located at [ROOT_PROJECT]/public/assets/sound/sound.aiff (for iOS), and trying to load in the sound using the snippit below.

import { Plugins } from '@capacitor/core';
const { LocalNotifications } = Plugins;

LocalNotifications.schedule({
  notifications: [
    {
      title: "Title",
      body: "Body",
      id: 1,
      schedule: { at: new Date(Date.now() + 1000 * 5) },
      sound: 'assets/sounds/sound.aiff',
      attachments: null,
      actionTypeId: "",
      extra: null
    }
  ]
});

I’ve also tried applying file:// in front of it (got this from ionic), and using a direct path. I know that the sound exists at that path, and that it can be played, but I have no clue what needs to be done to make it play that sound.

If anyone has an idea on how to do it, please let me know!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
modernappsllccommented, Aug 29, 2020

Hey guys after long time testing, I have figured it out using the capacitor local notifications on any version of Android. *To get the sound working you must create a channel

First you need to put the sound.mp3 file that you have inside the raw folder located in the res folder of Android files.

Second you need to create a channel using the plugin and put in the right values, for (sound: ‘sound.mp3’). Then schedule a notification with the basic values but don’t include the sound param when you schedule the notification. Examples below

//// Creating channel example ///// const channel1: NotificationChannel = { id: ‘mychannel’, name: ‘channel’, importance: 5, sound: ‘sound.mp3’, visibility: 1,

}

Important NotificationChannel from capacitor plugins

Plugins.LocalNotification.createchannel(channel1)

//// Scheduling notifications ///// Plugins.LocalNotification.schedule({ notifications { title: ‘example’, id: 1, channel: ‘mychannel’ (channel id from above) body: ‘example’, trigger: ‘example’

} })

Third inside the capacitor.config.json file put Plugins { LocalNotification { “smallicon”: “icon” “Iconcolor”: "#22222# “sound”: “sound.mp3” } }

That’s all after that it will be working. Once your notification triggers it will play the custom sound you assigned. If you get confused let me know. Here is the video you can follow to help you understand better. https://youtu.be/bww4a4B43tM

2reactions
Maraaghibcommented, Dec 15, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

[LOCAL NOTIFICATION PLUGIN] how to use a custom sound
[LOCAL NOTIFICATION PLUGIN] how to use a custom sound · 1. Make sure your audio file is in . · 2. Sound should...
Read more >
flutter_local_notifications | Flutter Package - Pub.dev
A cross platform plugin for displaying and scheduling local notifications for Flutter applications with the ability to customise for each platform.
Read more >
UNNotificationSound | Apple Developer Documentation
For local notifications, assign the sound object to the sound property of your UNMutableNotificationContent object. For a remote notification, assign the ...
Read more >
Flutter Local Push Notification | Custom Sound - YouTube
Flutter Local Push notification setup and custom soundAlso done basic setup mp4 file is using only for reference purpose.
Read more >
Add mp3 sound in flutter_local_notifications - Stack Overflow
implement your local notification code: var androidPlatformChannel = new AndroidNotificationDetails( "your_channel_id", "name", ...
Read more >

github_iconTop Related Medium Post

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