Android 使用蓝牙耳机录音(语音识别)

Android 使用蓝牙耳机录音(语音识别),android,bluetooth,voice-recognition,headset,Android,Bluetooth,Voice Recognition,Headset,我尝试在我的应用程序中添加一个功能,您可以通过蓝牙耳机与它通信 我有这样的东西: BluetoothHeadset mBluetoothHeadset; AudioManager mAudioManager; // Get the default adapter BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); private BluetoothProfile.ServiceListener mP

我尝试在我的应用程序中添加一个功能,您可以通过蓝牙耳机与它通信

我有这样的东西:

BluetoothHeadset mBluetoothHeadset;
AudioManager mAudioManager;
// Get the default adapter
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
private BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
    public void onServiceConnected(int profile, BluetoothProfile proxy) {
        if (profile == BluetoothProfile.HEADSET) {
            mBluetoothHeadset = (BluetoothHeadset) proxy;
            Log.d("bt", "connected");
            // mAudioManager.startBluetoothSco();
            Log.d("bt",
                    "devices:"
                            + Integer.toString(mBluetoothHeadset
                                    .getConnectedDevices().size()));
            if (mBluetoothHeadset.startVoiceRecognition(mBluetoothHeadset
                    .getConnectedDevices().get(0))) {
                Log.d("bt", "recognize");
                myRecognizer.startListening(); // this starts google voice recognition;
            } else
                Log.d("bt", "no recognize");
        }
    }

    public void onServiceDisconnected(int profile) {
        if (profile == BluetoothProfile.HEADSET) {
            mBluetoothHeadset = null;
            Log.d("bt", "disconnected");
        }
    }
};
在“我的活动”中的OnResume中:

mAudioManager = ((AudioManager) getSystemService(AUDIO_SERVICE));
if (mAudioManager.isBluetoothScoAvailableOffCall()) {

    mBluetoothAdapter.getProfileProxy(this, mProfileListener,
            BluetoothProfile.HEADSET);
    Log.d("bt", "true");

} else {
    Log.d("bt", "false");
}
日志:

bt true
bt connected
bt devices 1
bt recognize

它仍然使用内置麦克风,而不是BT耳机麦克风。

我也一直在研究这个问题。。。我认为这是一个蓝牙协议呼叫问题。似乎当您使用耳机启动通话时,麦克风会跳到手机上。但如果您从应用程序(而不是手机或耳机)启动麦克风,则使用的麦克风是内置麦克风。我不知道怎么解决,你找到答案了吗?