找回密码
 注册
搜索
查看: 1782|回复: 0

[讨论] MEDIA_BUTTON广播

[复制链接]
发表于 2013-9-6 17:00:24 | 显示全部楼层 |阅读模式
本帖最后由 tangmin0719 于 2013-9-6 17:03 编辑


1.        MEDIA_BUTTON广播比较特殊,是顺序广播,由AudioService对MEDIA_BUTTON广播进行处理。

2.        MEDIA_BUTTON广播的注册者,同时如果在AudioManager中注册,则该应用将会成为MEDIA_BUTTON的唯一接收器。
也就是说在AudioManager中注册了之后,AudioService会将MEDIA_BUTTON广播发给audioSercie注册者,其他的MEDIA_BUTTON广播注册者将收不到MEDIA_BUTTON广播了,这样避免多个应用都去接收此广播造成一定的混乱。

mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        ComponentName rec = new ComponentName(getPackageName(),
                MediaButtonIntentReceiver.class.getName());
        mAudioManager.registerMediaButtonEventReceiver(rec);

但AudioService只会将 MEDIA_BUTTON广播发给某一个 应用,也就是说AudioService会利用一个栈来管理所有audioSercie的注册者,新注册的应用总是会位于栈顶。
当AudioService发送MEDIA_BUTTON广播时,作如下处理:
a)当phone在接打电话时,优先被处理。
否则,
b) 如果栈为空,则不对MEDIA_BUTTON广播做任何处理,直接发送。MEDIA_BUTTON广播的注册者 按优先顺序接收  MEDIA_BUTTON广播。
c) 如果栈不为空,那么指定由栈顶的那个注册者去接收MEDIA_BUTTON广播。


3.     在4.1中PhoneWindowManager.interceptKeyBeforQueueing方法中发送。
在4.2有比较大的改动,调用堆栈:
KeyGuardViewBase.interceptMediaKey()-->handleMediaKeyEvent()

-->AudioService.dispatchMddiaKeyEvent();

-->dispatchMediaKeyEventForCalls(最先处理)或者filterVoiceInputKeyEvent或者dispatchMediaKeyEvent 音乐类应用处理。

注册方式,音乐类应用通过registerMediaButtonEventReceiver注册,电话应用通过registerMediaButtonEventReceiverForCalls注册。


高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2024-5-5 01:48 , Processed in 0.043964 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表