I am trying to create a notification and play a sound. the following code mostly works.
NotificationManager notificationManager = (NotificationManager)Android.App.Application.Context.GetSystemService(Context.NotificationService);
Notification.Builder builder = new Notification.Builder(Android.App.Application.Context);
builder.SetSound(uri);
builder.SetAutoCancel(true);
builder.SetContentTitle(action);
builder.SetContentText(body);
builder.SetSmallIcon(Resource.Drawable.ACLogo);
builder.SetDefaults(vibrate ? NotificationDefaults.All : NotificationDefaults.Sound);
builder.SetOngoing(false);
notificationManager.Notify(1010, builder.Build());
I am pulling the uri from one out of the list of ringtones on the device. This has several issues.
1st, builder.SetSound(uri) is deprecated. All forms of it seem to be, so what is the replacement for it?
2nd, build.SetDefaults(...) is also deprecated.
3rd, if I issue build.SetDefaults, then it does not play the sound I am setting.
4th, if I don't issue build.SetDefaults, it plays the correct sound, but keeps playing it over and over.
I only want the sound to play one time. It is supposed to be more like an alert sound, like when a text message shows up, not like the phone ringing until you answer it.
I can't seem to find answers to how to actually make this work. Even when I was just trying to play a sound instead of create a notification, I didn't really see what the answer was to how ringtone.Play() can be limited to only once instead of looping until ringtone.Stop() is issued.