在android中捕获蓝牙耳机longpress事件

在android中捕获蓝牙耳机longpress事件,android,bluetooth,Android,Bluetooth,我想在长按蓝牙按钮时启动我的主要活动,就像长按BT按钮时启动Google Voice一样,但我似乎找不到正确的操作来触发它 我当前的代码: public class LaunchReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction();

我想在长按蓝牙按钮时启动我的主要活动,就像长按BT按钮时启动Google Voice一样,但我似乎找不到正确的操作来触发它

我当前的代码:

public class LaunchReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.d("HERE", action);
    }
}
在舱单中:

    <receiver
        android:name="com.app.LaunchReceiver"
        android:enabled="true" >
        <intent-filter>
            <action android:name="android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED" />
            <action android:name="android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT" />
            <action android:name="android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED" />
            <action android:name="android.intent.action.VOICE_COMMAND" />
            <action android:name="android.intent.action.WEB_SEARCH" />
            <action android:name="android.intent.action.MEDIA_BUTTON" />
        </intent-filter>
    </receiver>

现在,使用上面的代码,显示的唯一动作是连接状态改变,但当您打开/关闭耳机时也会发生这种情况。我一直在stackoverflow中尝试其他答案,但没有成功

---编辑---解决方法是:

    <activity
        android:name="com.app.LaunchActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter android:priority="2147483647">
            <action android:name="android.intent.action.VOICE_COMMAND" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>


并在应用程序管理器中禁用S语音。

根据我对android中bluedroid和蓝牙应用程序(软件包/应用程序/蓝牙)的理解

无论何时按下耳机中的蓝牙按钮,它都会发送AT+BVRA命令(查看蓝牙hfp规范1.5/1.6),该命令要求手机启动语音识别

bluedroid源代码 btif/src/btif_hf.c->BTA_AG_AT_BVRA_EVT调用BTHF_VR_STATE_启动

翻译成

/软件包/apps/Bluetooth/+/android-4.4.2_r1/src/com/android/Bluetooth/hfp/HeadsetStateMachine.java

processVrEvent->startActivity(sVoiceCommandIntent); 其中sVoiceCommandIntent是动作\语音\命令


因此,语音识别没有广播意图。

如果我错了,请纠正我,但根据我在HeadsetStateMachine.java中的理解。它使用intent.intent.action.VOICE_命令启动活动。考虑到这一点,我尝试在清单中的Launcher活动中添加一个意图过滤器,并尝试查看longpress是否会启动该活动。但到目前为止,该活动尚未启动。如果我错了,请原谅我,因为我对处理蓝牙很不熟悉。看来是她的声音起了作用。谢谢你的帮助@kiirohana的语音意味着SCO语音?啊,我在三星手机上测试它,所以它安装了s语音。所以,我现在只是禁用了她的声音。