Hello,
Changing the playback device in Android can only be done in call mode. In iOS, users can only select the playback device through the control center.
On the Android platform, you can refer to the following code to set the call mode and change the playback device.
Step 1. Instantiate MainActivity
.
public class MainActivity : MauiAppCompatActivity
{
public static MainActivity Instance { get; private set; }
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
Instance = this;
}
}
Step 2. Create the AudioHelper
class in Android
folder.
public static class AudioHelper
{
public static void PlayWithSpeaker()
{
AudioManager audioManager = (AudioManager)MainActivity.Instance.GetSystemService(Context.AudioService);
audioManager.Mode = Mode.InCommunication;
audioManager.BluetoothScoOn = false;
audioManager.SpeakerphoneOn = true;
}
public static void PlayWithBluetooth()
{
AudioManager audioManager = (AudioManager)MainActivity.Instance.GetSystemService(Context.AudioService);
audioManager.Mode = Mode.InCommunication;
audioManager.BluetoothScoOn = true;
audioManager.SpeakerphoneOn = false;
audioManager.StartBluetoothSco();
}
}
Step 3. Invoke the method on maui.
#if ANDROID
AudioHelper.PlayWithSpeaker();
#endif
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.