您可以在Firebase通知中设置特定的铃声。
[使用API 26或更高版本时,将使用通知通道。使用通道的SetSound
可以覆盖默认的通知声音。
使用通道的SetSound
方法设置铃声。
channel.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Ringtone),alarmAttributes);
创建频道的完整代码:
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);
}
您可以从下面的链接下载有关Firebase通知的代码示例。用通道的SetSound
进行更改将设置特定的铃声。https://docs.microsoft.com/en-us/samples/xamarin/monodroid-samples/firebase-fcmnotifications/