问题
How i can force the push notification to run ringtone instead of default notification sound is there any way to ovveride the default behaviour for firebase onMessageReceived
回答1:
You could set the specific ringtone in firebase notification.
When you use API 26 or later, you would use Channel of Notification. Use the SetSound
of channel would cover the default notification sound.
Set the Ringtone with SetSound
method of Channel.
channel.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone),alarmAttributes);
The whole code of creating channel:
void CreateNotificationChannel()
{
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 channel = new NotificationChannel(CHANNEL_ID, "FCM Notifications", NotificationImportance.Default)
{
Description = "Firebase Cloud Messages appear in this channel"
};
channel.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone),alarmAttributes);
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
notificationManager.CreateNotificationChannel(channel);
}
You could download the code sample about Firebase notification from the link below. Do the change with SetSound
of channel would set the specific Ringtone.
https://docs.microsoft.com/en-us/samples/xamarin/monodroid-samples/firebase-fcmnotifications/
来源:https://stackoverflow.com/questions/62345876/specific-ringtone-firebase-notification-xamarin-android