如何检测蓝牙通话/媒体按钮$在Android应用p $ PSS [英] How to detect bluetooth call/media button press in android app

查看:408
本文介绍了如何检测蓝牙通话/媒体按钮$在Android应用p $ PSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检测我的应用程序的蓝牙设备按钮的点击。我也跟着许多计算器链接,但似乎并没有为我工作。

I need to detect the bluetooth device button click in my application. i followed many stackoverflow links, but doesn't seem to work for me.

我使用的广播接收器,如下所示:

I am using the broadcast receiver as shown below:

public class RemoteControlReceiver extends BroadcastReceiver {    
    @Override    
    public void onReceive(Context context, Intent intent) {    
        if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {    
            KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);    
            if (KeyEvent.KEYCODE_MEDIA_PLAY == event.getKeyCode()) {    
                //call my method    
            }    
        }    
    }    
}

和我的表现如下:

<receiver android:name=".RemoteControlReceiver" >    
   <intent-filter>    
       <action android:name="android.intent.action.MEDIA_BUTTON" />    
       <category android:name="android.intent.category.DEFAULT"/>    
   </intent-filter>    
</receiver>

任何一个可以提出一个出路?
先谢谢了。

can any one suggest a way out? Thanks in advance.

推荐答案

是您的API级别至少有11个?在code键,code_MEDIA_PLAY在API层面11.自KEY code_MEDIA_PLAY_PAUSE code存在加入API级别3。

Is your API level at least 11? The code KEYCODE_MEDIA_PLAY was added in API level 11. The KEYCODE_MEDIA_PLAY_PAUSE code exists since API level 3.

此外,你试图不指定类别配置你的意图过滤器?

Also, have you tried to configure your intent filter without specifying a category?

是您RemoteControlReceiver类根包您的应用程序?它可能一直没能找到.RemoteControlReceiver。

Is your RemoteControlReceiver class in the root package of your application? It might have not been able to find ".RemoteControlReceiver".

除此之外,我看不到,你可以做任何事。

Other than that, I can't see where you could be doing anything wrong.

我读过的,你可能需要也呼吁registerMediaButtonEventReceiver和unregisterMediaButtonEventReceiver几个职位。您是否尝试过这个?

I've read in a few posts that you might have to also call registerMediaButtonEventReceiver and unregisterMediaButtonEventReceiver. Have you tried this?

要进行注册:

audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
componentName = new ComponentName(getPackageName(),
    RemoteControlReceiver.class.getName());
audioManager.registerMediaButtonEventReceiver(componentName);

和注销:

audioManager.unregisterMediaButtonEventReceiver(componentName);

这篇关于如何检测蓝牙通话/媒体按钮$在Android应用p $ PSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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