question

UniversalCamera-5217 avatar image
0 Votes"
UniversalCamera-5217 asked UniversalCamera-5217 answered

How to Turn-On SpeakerPhone on Android 11 without using Android.Media

            AudioManager am = (AudioManager)Android.App.Application.Context.GetSystemService(Context.AudioService);
             am.Mode = Mode.InCall;
             am.SpeakerphoneOn = true;


This works on Android 10 BUT not Android 11.

How can I accomplish turning on SpeakerPhone on Android 11.

Thank you!

dotnet-xamarin
· 9
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Is there any logs when you tested on android 11?

0 Votes 0 ·

Thank you

It run the code on both platform. Android 10 device turns on SpeakerPhone BUT Android 11 does not.

0 Votes 0 ·

Any updates? Have you got the solution?

0 Votes 0 ·

Thank you

No solution...I got closed on StackOverflow on this question.

0 Votes 0 ·
zyz629 avatar image zyz629 UniversalCamera-5217 ·

Maybe we can go to google Community to consult this problem: https://support.google.com/voice/thread/73464905?hl=en .

1 Vote 1 ·
Show more comments

Hi @UniversalCamera-5217 , Sorry so late to response because the latest PT tool can not refresh the status in time. Could you please post a basic demo to github or onedriver so that we can test on our side?

0 Votes 0 ·

Thank you

I followed my hunch that the OS was not releasing SpeakerPhone ON condition when the Native PhoneApp was closed. So I re-wrote the DependencyService to clean-up the resources after the call is terminated. Now its working fine!

Thank you

0 Votes 0 ·

Congrats, could you please post your answer here so that it will help others who have similar threads? Thanks in advance.

0 Votes 0 ·

1 Answer

UniversalCamera-5217 avatar image
0 Votes"
UniversalCamera-5217 answered

namespace MomTextCamera.Droid.Receivers
{
[BroadcastReceiver(Enabled = true, Exported = true)]
[IntentFilter(new[] { TelephonyManager.ActionPhoneStateChanged })]
public class PhoneCallListener : BroadcastReceiver
{
AudioManager audioManager = (AudioManager)Android.App.Application.Context.GetSystemService(Context.AudioService);

     public override void OnReceive(Context context, Intent intent)
     {
         var state = intent.GetStringExtra(TelephonyManager.ExtraState);
         GlobalEvents.OnPhoneCallReceived_Event(this, new PhoneCallEventArgs() { State = state });
         var b1 = !App.JayPhoneNumber.Contains(App.CurrentPhoneNumber);
         var b2 = App.ContactList.Any(s => s.Contains(App.CurrentPhoneNumber));

         if (intent.Action == TelephonyManager.ActionPhoneStateChanged)
         {
             if (state == TelephonyManager.ExtraStateRinging)
             {
                 //number = intent.GetStringExtra(TelephonyManager.ExtraIncomingNumber);
                 //number = intent.Extras.GetString(TelephonyManager.ExtraIncomingNumber);
             }
             else if (state == TelephonyManager.ExtraStateOffhook && b2 && b1)
             {
                 //audioManager.Mode = Mode.InCall;// | Mode.Ringtone;
                 //Task.Delay(5000).Wait();
                 audioManager.SpeakerphoneOn = true;
             }
             else if (state == TelephonyManager.ExtraStateIdle && b2 && b1)
             {
                 audioManager.SpeakerphoneOn = false;
             }
         }
     }
 }

}

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.