thudugala / thudugala/Plugin.LocalNotification

Android : Issue having multiple sounds

Open
#448 11 comments 0 reactions 1 assignee View on GitHub

@thudugala is already working on this.

Since Sep 1, 2023.

Android Configuration Issue
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.