为什么Android 6.0+需要RECORD_AUDIO权限才能发送Intent.ACTION_HEADSET_PLUG

时间:2017-06-12 09:49:14

标签: android android-intent android-6.0-marshmallow android-permissions

我有一个BroadcastReceiver,我在运行时构建并注册以接收Intent.ACTION_HEADSET_PLUG,以便在插入耳机或拔下耳机时收到通知。

在Android 6.0之前,这种方式运行良好,但从那时起,只有在RECORD_AUDIO权限被授予后才会收到意图。

我本来想使用该Intent的通知向用户询问RECORD_AUDIO权限,但现在我没有明确要求这样做。因此,无论他们是否对音频感兴趣,我都必须要求获得启动许可。

我无法理解为什么该应用需要RECORD_AUDIO才知道您是否已插入耳机。

有没有办法在Android 6.0+中定位ACTION_HEADSET_PLUG而不需要RECORD_AUDIO并定位Android 23 +?

注意系统确实识别出已插入耳机(系统日志如下所示),但ACTION_HEADSET_PLUG未发送到我的应用,除非已授予RECORD_AUDIO

06-13 22:18:21.176 5509-7053/? V/WiredAccessoryManager: notifyWiredAccessoryChanged: when=24261279475000 bits=SW_HEADPHONE_INSERT SW_MICROPHONE_INSERT mask=94
06-13 22:18:21.177 5509-7053/? V/WiredAccessoryManager: newName=h2w newState=1 headsetState=1 prev headsetState=0
06-13 22:18:21.177 5509-7053/? I/WiredAccessoryManager: MSG_NEW_DEVICE_STATE
06-13 22:18:21.178 5509-5509/? V/WiredAccessoryManager: headsetName:  connected
06-13 22:18:21.205 4345-4345/? I/AudioFlinger: openOutput(), module 10 Device 4, SamplingRate 8000, Format 0x1000000, Channels 1, flags 31
06-13 22:18:21.206 4345-4345/? I/AudioFlinger: HAL output buffer size 262144 frames, normal sink buffer size 262144 frames
06-13 22:18:21.215 4345-26896/? I/AudioFlinger: AudioFlinger's thread 0xe94fc000 ready to run
06-13 22:18:21.227 4345-26896/? D/audio_hw_primary: out_set_parameters: enter: usecase(3: compress-offload-playback) kvpairs: closing=true
06-13 22:18:21.227 4345-4345/? D/audio_hw_primary: out_set_parameters: enter: usecase(3: compress-offload-playback) kvpairs: exiting=1
06-13 22:18:21.229 4345-26892/? E/audio_hw_primary: offload_thread_loop: Compress handle is NULL
06-13 22:18:21.230 4345-4696/? D/audio_hw_primary: out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=0
06-13 22:18:21.237 4345-26897/? I/AudioFlinger: AudioFlinger's thread 0xe6e039c0 ready to run
06-13 22:18:21.239 4345-26898/? I/AudioFlinger: AudioFlinger's thread 0xe6d83dc0 ready to run
06-13 22:18:21.248 8921-8921/? V/MediaRouter: Updating audio routes: AudioRoutesInfo{ type=HEADSET }
06-13 22:18:21.248 8921-8921/? V/MediaRouter: Dispatching route change: RouteInfo{ name=Headphones, description=null, status=null, category=RouteCategory{ name=null types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO  groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=null }
06-13 22:18:21.250 25097-25097/? V/MediaRouter: Updating audio routes: AudioRoutesInfo{ type=HEADSET }
06-13 22:18:21.251 25097-25097/? V/MediaRouter: Dispatching route change: RouteInfo{ name=Headphones, description=null, status=null, category=RouteCategory{ name=null types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO  groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=null }
06-13 22:18:21.253 5509-5509/? V/MediaRouter: Updating audio routes: AudioRoutesInfo{ type=HEADSET }
06-13 22:18:21.253 5509-5509/? V/MediaRouter: Dispatching route change: RouteInfo{ name=Headphones, description=null, status=null, category=RouteCategory{ name=null types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO  groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=null }
06-13 22:18:21.274 7274-7335/? I/vol.Events: writeEvent level_changed STREAM_VOICE_CALL 5
06-13 22:18:21.275 7274-7335/? I/vol.Events: writeEvent level_changed STREAM_SYSTEM 7
06-13 22:18:21.282 7274-7274/? V/MediaRouter: Updating audio routes: AudioRoutesInfo{ type=HEADSET }
06-13 22:18:21.282 7274-7274/? V/MediaRouter: Dispatching route change: RouteInfo{ name=Headphones, description=null, status=null, category=RouteCategory{ name=null types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO  groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=null }
06-13 22:18:21.300 5509-5509/? I/Telecom: WiredHeadsetManager: ACTION_HEADSET_PLUG event, plugged in: true, : WHC.oADA@A60
06-13 22:18:21.302 5509-7538/? I/Telecom: CallAudioRouteStateMachine: Message received: CONNECT_WIRED_HEADSET=1, arg1=0: WHC.oADA->CARSM.pM_CONNECT_WIRED_HEADSET@A60_0
06-13 22:18:21.303 5509-7538/? I/Telecom: Telecom: Non-call EVENT: AUDIO_ROUTE, Wired headset connected: WHC.oADA->CARSM.pM_CONNECT_WIRED_HEADSET@A60_0
06-13 22:18:21.303 5509-7538/? I/Telecom: CallAudioRouteStateMachine: Message received: SWITCH_HEADSET=1003, arg1=0: WHC.oADA->CARSM.pM_CONNECT_WIRED_HEADSET->CARSM.pM_SWITCH_HEADSET@A60_0_0
06-13 22:18:21.303 5509-7538/? I/Telecom: Telecom: Non-call EVENT: AUDIO_ROUTE, Leaving state QuiescentEarpieceRoute: WHC.oADA->CARSM.pM_CONNECT_WIRED_HEADSET->CARSM.pM_SWITCH_HEADSET@A60_0_0
06-13 22:18:21.303 5509-7538/? I/Telecom: Telecom: Non-call EVENT: AUDIO_ROUTE, Entering state QuiescentHeadsetRoute: WHC.oADA->CARSM.pM_CONNECT_WIRED_HEADSET->CARSM.pM_SWITCH_HEADSET@A60_0_0

0 个答案:

没有答案