Reputation:
is it possible to use custom sounds in xamarin android for background notification? I didnt find any examples.
Upvotes: 0
Views: 842
Reputation: 1513
Yep! Here's an example:
var pathToPushSound = $"android.resource://com.your.package/raw/{soundName}";
var soundUri = Android.Net.Uri.Parse(pathToPushSound);
var builder = new NotificationCompat.Builder(_context)
.SetContentTitle("TITLE")
.SetContentText("TEXT")
.SetPriority(1)
.SetSmallIcon(Resource.Drawable.TransparentLogo)
.SetOngoing(true)
.SetSound(soundUri);
builder.Build();
The URI
is the path to the resource where your sound file lives, then you set that URI
in your NotificationBuilder
using the SetSound
method.
Upvotes: 1