android -how to listen to SpeakerPhone change

460 Views Asked by At

I'd like to be able to listen to on/off events of the android native speakerphone button.

Realizing i could spawn a child thread and keep checking for AudioManager.isSpeakerphoneOn(); thats just going to kill battery life etc etc. Is there a listener for this ?

1

There are 1 best solutions below

0
On BEST ANSWER

Starting from API 29, you can register a BroadcastReceiver using the Intent filter AudioManager.ACTION_SPEAKERPHONE_STATE_CHANGED.

Documentation is available in the Android official page here.

Unfortunately I didn't found any other way except polling, for APIs < 29.