MEDIA_BUTTON handle not working when starting bluetoothSCO

I am using a bluetooth speaker audio recorder. The bluetooth speaker has a multimedia button like play / pause, next, previous. I start the play button to record and click again to stop. But the problem is that when using mAudioManager.startBluetoothSco () to use bluetooth microphone for recording, Media_button receiver no longer works, cannot receive any event.

Below is the source code: Recipient registration:

    ((AudioManager) getSystemService(AUDIO_SERVICE)).registerMediaButtonEventReceiver(
            new ComponentName(



    public void onReceive(Context context, Intent intent) {
        Log.d("MediaButtonReceiver", "onReceive Media button!" );
        KeyEvent key = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        Log.d("MediaButtonReceiver", "Media button! action: [" + key.getAction() + "] key code: [" + key.getKeyCode() + "]");
        if(key.getAction() == KeyEvent.ACTION_UP) {
            int action = fromKeyCodeToAction(key.getKeyCode());
            switch (action) {
                case ACTION_START_STOP_TALKING:
                    LogUtils.LOGD("MediaButtonReceiver", "Action start/stop");


... I am handling some logic in the listener to check the current state entry or not. and start the service to start or stop recording. And this is the code to start recording.

if (isBluetoothHeadsetConnected) {
                LogUtils.LOGI("Bluetooth", "record using headset");
                //we just start recording when the audio state is connected
                mContext.registerReceiver(mBluetoothAudioStateBroadcastReceiver, mBluetoothAudioStateIntentFilter);
                LogUtils.LOGI("Bluetooth", "startBluetoothSco");
            } else {
                LogUtils.LOGI("Bluetooth", "record normally ");


If I remove startBluetoothSco () the receiver works fine, but the app uses the device microphone instead of the bluetooth speaker. If I don't delete, the receiver no longer works and I cannot stop the recorder. Do you have a solution to work arround?


source to share

All Articles