问题
How I can send a notification to xamarin.android project to make the phone ring like calling I tried to create raw folder inside Resource and set my ringtone their but unfortunately it's not working
is there any solution ?
回答1:
Create a raw folder in Resource and put the mp3 file in it with AndroidResource
Build Action.
Set the custom sound of Notification channels would cover the default sound.
You could use the custtom Notification via SetSound
of channel.
The Whole of creating channel:
void CreateNotificationChannel1()
{
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{
// Notification channels are new in API 26 (and not a part of the
// support library). There is no need to create a notification
// channel on older versions of Android.
return;
}
var alarmAttributes = new AudioAttributes.Builder()
.SetContentType(AudioContentType.Sonification)
.SetUsage(AudioUsageKind.Notification).Build();
var path = Android.Net.Uri.Parse("android.resource://com.companyname.NotificationChannelsDemo/" + Resource.Raw.Hello);
var name = Resources.GetString(Resource.String.channel_name);
var description = GetString(Resource.String.channel_description);
var channel = new NotificationChannel(CHANNEL_ID1, name, NotificationImportance.Max)
{
Description = description
};
channel.SetSound(path, alarmAttributes);
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.CreateNotificationChannel(channel);
}
For more information about how to use channel of notification, you could check the link below. https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/notifications/local-notifications-walkthrough
来源:https://stackoverflow.com/questions/62369695/custom-notification-sound-firebase