specific ringtone firebase notification xamarin.android

主宰稳场 提交于 2021-02-10 05:48:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!