简体   繁体   English

android - 如何收听SpeakerPhone更改

[英]android -how to listen to SpeakerPhone change

I'd like to be able to listen to on/off events of the android native speakerphone button.我希望能够收听 android 原生扬声器按钮的开/关事件。

Realizing i could spawn a child thread and keep checking for AudioManager.isSpeakerphoneOn();意识到我可以产生一个子线程并继续检查 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 .API 29开始,您可以使用 Intent 过滤器AudioManager.ACTION_SPEAKERPHONE_STATE_CHANGED注册BroadcastReceiver

Documentation is available in the Android official page here .文档可在此处的 Android 官方页面中找到

Unfortunately I didn't found any other way except polling, for APIs < 29.不幸的是,对于 API < 29,除了轮询之外,我没有找到任何其他方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM