Xamarin.Android get resource id without ResourceManager.

If calling ResourceManager.GetResource(“resourceName”) doesn’t work because the framework doesn’t return the resource you want, you can bypass it with the following code snippet:

            string audioFileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(audiofile);
            int audioResourceId = (int)typeof(Resource.Raw).GetField(audioFileNameWithoutExtension).GetValue(null);
            Android.Net.Uri audioUri = Android.Net.Uri.Parse(ContentResolver.SchemeAndroidResource + "://" + Application.Context.PackageName + "/" + audioResourceId);

            channel.SetSound(audioUri, audioAttributes);

I used this code snippet to set a custom push notification sound

This content has 6 months. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.