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 ?
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.