thudugala / thudugala/Plugin.LocalNotification
Android : Issue having multiple sounds
@thudugala is already working on this.
Since Sep 1, 2023.
- Dominant language
- C#
- Stars
- 474
- Forks
- 73
- PR merge metrics
- No merged PRs in 30d
Description
Hi there,
First, thanks a lot about your fantastic work, @thudugala, the functionnality and usage is really simple and straightforward.
However, I can't make multiple sounds to work on Android. One works fine, but if I want to add more, it does not work : only the first one I declare in .AddAndroid is played :
My files (legit_01.mp3 and legit_02.mp3) are located in Platforms/Android/Resources/raw
I did some tests (uninstalling / reinstalling the app before each test).
Here is how I call my notification. I want to be able to change the sound just by changing "legit_01" to "legit_02" :
// Create the request itself
var request = new NotificationRequest
{
NotificationId = Convert.ToInt32(NotificationId),
Title = $"{theNotif.Description} coming at {theNotif.TimeEvent:HH:mm}",
Subtitle = "", // Appear on the right side of the title (optionnal)
Description = theNotif.Category,
// CategoryType, defined in MauiProgram.cs' config is the list of buttons available for actions
CategoryType = NotificationCategoryType.Status,
Sound = DeviceInfo.Platform == DevicePlatform.Android ? "legit_01" : "legit_01.mp3", // or legit_02
Schedule = new NotificationRequestSchedule
{
// Set it based on the week day
NotifyTime = TargetDate,
RepeatType = NotificationRepeat.TimeInterval,
NotifyRepeatInterval = TimeSpan.FromDays(7)
}
};
LocalNotificationCenter.Current.Show(request);
And how I create my two channels :
.UseLocalNotification(config =>
{
config.AddCategory(new NotificationCategory(NotificationCategoryType.Status)
{
ActionList = new HashSet<NotificationAction>(new List<NotificationAction>()
{
new NotificationAction(1337)
{
Title = "MUTE",
Android = { LaunchAppWhenTapped = true }
}
})
})
.AddAndroid(android =>
{
android.AddChannel(new NotificationChannelRequest { Sound = "legit_01" });
android.AddChannel(new NotificationChannelRequest { Sound = "legit_02" });
});
})
After multiple tests, it's always the first one defined in .AddAndroid that is played, whatever the value of the "Sound" parameter I give to the NotificationRequest. If I switch the AddChannel (e.g. : legit_02 first), it will play legit_02 first, no matter which legit_XX I put in the "Sound" parameter. If I give a random "Sound" parameter though, no sound is played - as if it didn't find the file (which is correct and expected).
Based on the docs, I tried to add Id and Names to the Channels, like so :
.UseLocalNotification(config =>
{
config.AddCategory(new NotificationCategory(NotificationCategoryType.Status)
{
ActionList = new HashSet<NotificationAction>(new List<NotificationAction>()
{
new NotificationAction(1337)
{
Title = "MUTE",
Android = { LaunchAppWhenTapped = true }
}
})
})
.AddAndroid(android =>
{
android.AddChannel(new NotificationChannelRequest { Id=$"legit_01", Name="legit_01", Description="legit_01", Sound = "legit_01" });
android.AddChannel(new NotificationChannelRequest { Id=$"legit_02", Name="legit_02", Description="legit_02", Sound = "legit_02" });
});
})
But this behaves even worse : the default sound of my device (which is already a custom one) is played.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.