广播接收器的最高优先级不起作用 [英] Broadcast receiver highest priority not working

查看:220
本文介绍了广播接收器的最高优先级不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ACTION_MEDIA_BUTTON处理程序来做一个应用程序,但看来它总是被MX Player或Apollo拦截,我没有意图

I'm doing an application using ACTION_MEDIA_BUTTON handler, but it appears it is always intercepted by MX Player or Apollo and I get no Intent

我已经尝试了在标记中设置的1000和2147483647优先级,并在设置setPriority的构造函数之后直接尝试了

I've tried both 1000 and 2147483647 priority set in tag and directly after constructor with setPriority

在不存在MX Player或Apollo的情况下,应用程序可以正常工作

Applications works when no MX Player or Apollo is present

我也尝试过使用Google Play的Headset Interceptor应用程序,我试图通过Autostarts应用程序拒绝向MX Player播放事件-没有帮助

I've also tried using Headset Interceptor app from google play, I tried to deny events to MX Player with Autostarts application - nothing helps

在onCreate中:

in onCreate:

IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
filter.addAction(Intent.ACTION_HEADSET_PLUG);
filter.setPriority(1000);
registerReceiver(receiver, filter);

在接收器中

@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

清单中

<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>

推荐答案

要捕获耳机按钮,也应该在Activity中的onCreate中将接收者也注册到媒体中

To capture headset button one should register receiver in media too in onCreate in Activity

AudioManager manager = (AudioManager) getSystemService(AUDIO_SERVICE);
manager.registerMediaButtonEventReceiver(new ComponentName(getPackageName(), BCreceiver.class.getName()));

这篇关于广播接收器的最高优先级不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆