How to play audio through Bluetooth speaker even when headset is plugged in?

前端 未结 5 601
夕颜
夕颜 2021-02-06 00:53

I have my phone connected to a Bluetooth speaker and the headphones plugged in. Now I\'d like to play audio through the Bluetooth speaker. When I set the audio stream to A

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-06 00:58

    Audiomanager overrides and routes audio to the latest connected device(either wired headset or bluetooth headset). In android, we do not have any option to override this setting unless it is a system app and route the audio wherever we wish to route. However, you can use reflection apis and override this setting. Audiomanager suspends bluetooth connection route(if already connected)if wired headset is connected and vice versa. You can look at the code here.

    Hence using reflection apis you can toggle bluetooth audio route by invoking this method.

提交回复
热议问题