Max*_*Cat 7 android broadcast headset android-intent
我正在使用ACTION_MEDIA_BUTTON处理程序执行一个应用程序,但它似乎总是被MX Player或Apollo截获,我没有得到Intent
我已尝试在标记中设置1000和2147483647优先级,并在构造函数后直接使用setPriority
当没有MX Player或Apollo时,应用程序可以正常运行
我也试过使用谷歌播放的Headset拦截器应用程序,我试图通过自动启动应用程序拒绝事件到MX Player - 没什么帮助
in onCreate:
IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
filter.addAction(Intent.ACTION_HEADSET_PLUG);
filter.setPriority(1000);
registerReceiver(receiver, filter);
Run Code Online (Sandbox Code Playgroud)
在接收者
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
// NEVER REACHES HERE WHEN MX PLAYER PRESENT. WORKS IF NOT
Run Code Online (Sandbox Code Playgroud)
在清单中
<receiver
android:name="BCreceiver"
android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.MEDIA_BUTTON" />
<action android:name="android.intent.action.HEADSET_PLUG" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
Vip*_*rma 13
请参阅以下链接中的" 值必须大于-1000且小于1000 "的行,最高优先级为999而不是1000.
http://developer.android.com/guide/topics/manifest/intent-filter-element.html
要捕获耳机按钮,还应该在 Activity 的 onCreate 中在媒体中注册接收器
AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE);
manager.registerMediaButtonEventReceiver(new ComponentName(getPackageName(), BCreceiver.class.getName()));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15512 次 |
| 最近记录: |