Jump to content
bcvs

Notifications individual Sound doesn't work

Recommended Posts

Hi everybody,

 

I want my App to fire notifications with my own individual sound.

 

When I read the documentation and different tutorials and forum posts this seems to be easyly done:

 

Notification := NotificationCenter1.CreateNotification;
Notification.EnableSound:=true;
Notification.SoundName:= MySoundfile;

 

But when I do so, Android uses still the default notification sound and under iOS I here nothing at all.

 

On both platforms I can play the sound using the TMediaplayer. So I know that the Soundfile is present on the phone and that MySoundfile is correct.

 

I use a mp3-File unter Android and a caf-File under iOS.

 

Delphi is V12

 

Any Ideas?

 

Share this post


Link to post
18 minutes ago, bcvs said:

When I read the documentation and different tutorials and forum posts this seems to be easyly done:

Which forum posts, and which tutorials?

19 minutes ago, bcvs said:

Notification.SoundName:= MySoundfile;

Sounds on Android are no longer associated with the notification itself, rather they are now associated with the channel via the SoundName property.

 

Note that you need to add the mp3 file to the deployment using a RemotePath of res\raw, and use the filename without the extension for the SoundName on the channel, e.g. for mysound.mp3, use a value of mysound for SoundName.

 

On iOS, you need to deploy the sound file with a RemotePath of .\, and use the actual filename for SoundName on the notification (i.e. not the channel)

Share this post


Link to post

Thank you for the hint with the channel but my first attempts were not succesful.

 

What I did: (according to https://docwiki.embarcadero.com/RADStudio/Athens/en/Using_Notifications)

 

- Deploy my soundfile notification.mp3 to remote path res\raw

 

- Create a Notification channel:

procedure TForm1.CreateDefaultNotificationChannel;
var
 NotificationChannel: TChannel;
begin
 NotificationChannel := NotificationCenter1.CreateChannel;
 NotificationChannel.Id := 'custom_notification_channel';
 NotificationChannel.Title := 'Custom notification channel';
 NotificationChannel.Description := 'Notification channel used for Firebase';
 NotificationChannel.Importance := TImportance.High; // NOTE: This is a 'heads-up notification'.
 NotificationChannel.SoundName:='notification';

 NotificationCenter1.CreateOrUpdateChannel(NotificationChannel);
end;

 

- This method is called once in TForm1.FormCreate.

 

- Setting the default 'notification channel id' in the project options, Application - Services to custom_notification_channel

 

Now the first problem:

When I check the generated AndroidManifest.xml, I don't find a 'meta-data' declaration for custom_notification_channel. Do I have to add something to the AndroidManifest.template.xml?

 

And the notification still play the default sound and not my notification.mp3

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×