Android上的蓝牙耳机按钮问题

时间:2016-07-06 14:12:25

标签: android bluetooth headset

问题是在startBluetoothSco()方法调用之后,没有调用MediaSession.Callback()的onMediaButtonEvent()方法。
所以,我使用这段代码:

mMediaSession.setCallback(new MediaSession.Callback() {
    public boolean onMediaButtonEvent(@NonNull Intent mediaButtonIntent) {
        Logging.d(TAG, "onMediaButtonEvent");
        return super.onMediaButtonEvent(mediaButtonIntent);
    }

        public void onPause() {
           Logging.d(TAG, "onPause");
           super.onPause();
        }

        public void onPlay() {
           Logging.d(TAG, "onPlay");
           super.onPlay();
        }

        public void onStop() {
            Logging.d(TAG, "onStop");
            super.onStop();
        }
});
mMediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
PlaybackState state = new PlaybackState.Builder()
        .setActions(                PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_PAUSE |
                                    PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PAUSE |
                                    PlaybackState.ACTION_SKIP_TO_NEXT | PlaybackState.ACTION_SKIP_TO_PREVIOUS)
        .setState(PlaybackState.STATE_STOPPED, PlaybackState.PLAYBACK_POSITION_UNKNOWN, 0)
        .build();
mMediaSession.setPlaybackState(state);
mMediaSession.setActive(true);
按下耳机按钮后,每次调用onMediaButtonEvent()方法,但之后

mAudioManager.startBluetoothSco();
它不再打电话了。它只能在以后调用
mAudioManager.stopBluetoothSco();
这个问题的解决方案是什么?

0 个答案:

没有答案