【发布时间】:2020-06-12 14:02:36
【问题描述】:
【问题讨论】:
标签: android firebase xamarin.android firebase-cloud-messaging
【问题讨论】:
标签: android firebase xamarin.android firebase-cloud-messaging
您可以在 firebase 通知中设置特定的铃声。
当您使用 API 26 或更高版本时,您将使用通知通道。使用SetSound的频道会覆盖默认通知声音。
使用Channel的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/
【讨论】: