Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to override notification volume when a push notification is received? iOS/Android

Hi,
I know this has been asked before but I can't find a solution that works for me.
I'm trying to get my app to turn up the volume of the notifications to 100% when a push notification is received but I just can't get this to happen.

I have tried using this solution for Android previously posted on these forums by @Cdn_Euro:

private void setNotificationVolumeToMax()
        {
            try
            {
                var audioManager = (AudioManager)GetSystemService(Context.AudioService);

                int max_volume = audioManager.GetStreamMaxVolume(Android.Media.Stream.Notification);
                audioManager.SetStreamVolume(Android.Media.Stream.Notification, max_volume, 0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        } 

This works, but only when called at some point along the Activity Lifecycle (OnCreate, OnPause etc.) or when the app is in the foreground.
I need this functionality to happen when the app is in the background to ensure that whenever a notification is received the user will hear it.

I'd really appreciate any help.

Best Answer

Answers

  • AelithiaAelithia Member

    Thank you so much! This is exactly what I needed :blush:

Sign In or Register to comment.