4

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 ?

j2emanue
  • 60,549
  • 65
  • 286
  • 456

1 Answers1

1

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.

Michele Bontorno
  • 1,157
  • 2
  • 13
  • 27