Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要创建一个在后台运行的服务,并检测是否正在使用电话扬声器。我需要收听电话“扬声器事件”(开或关)并根据扬声器的状态执行操作。
BroadcastReceiver您可以在动作中注册 a AudioManager.RINGER_MODE_CHANGED,当声音配置文件更改时将触发该动作。在里面onReceiver()你可以调用AudioManager'sgetRingerMode()方法,它会返回RINGER_MODE_NORMAL,RINGER_MODE_SILENT或RINGER_MODE_VIBRATE. 希望这可以帮助。
BroadcastReceiver
AudioManager.RINGER_MODE_CHANGED
onReceiver()
AudioManager
getRingerMode()
RINGER_MODE_NORMAL
RINGER_MODE_SILENT
RINGER_MODE_VIBRATE