Custom Notification Sound FireBase

吃可爱长大的小学妹 提交于 2021-01-29 06:16:54

问题


How I can send a notification to xamarin.android project to make the phone ring like calling I tried to create raw folder inside Resource and set my ringtone their but unfortunately it's not working

is there any solution ?


回答1:


Create a raw folder in Resource and put the mp3 file in it with AndroidResource Build Action.

Set the custom sound of Notification channels would cover the default sound.

You could use the custtom Notification via SetSound of channel.

The Whole of creating channel:

  void CreateNotificationChannel1()
    {
        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 path = Android.Net.Uri.Parse("android.resource://com.companyname.NotificationChannelsDemo/" + Resource.Raw.Hello);
        var name = Resources.GetString(Resource.String.channel_name);
        var description = GetString(Resource.String.channel_description);
        var channel = new NotificationChannel(CHANNEL_ID1, name, NotificationImportance.Max)
        {
            Description = description
        };
        channel.SetSound(path, alarmAttributes);
        var notificationManager = (NotificationManager)GetSystemService(NotificationService);
        notificationManager.CreateNotificationChannel(channel);
    }

For more information about how to use channel of notification, you could check the link below. https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/notifications/local-notifications-walkthrough



来源:https://stackoverflow.com/questions/62369695/custom-notification-sound-firebase

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