特定的铃声Firebase通知xamarin.android

问题描述 投票:2回答:1

我如何强制推送通知运行铃声而不是默认通知声音有什么办法可以ovfireide firebase onMessageReceived的默认行为 OnMessage Received not called

android firebase xamarin.android firebase-cloud-messaging
1个回答
1
投票

您可以在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/

© www.soinside.com 2019 - 2024. All rights reserved.