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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.