Bluetooth hands free client volume control

I have an android device acting as a hands free client device using hfp.

Using the following code:

I am able to receive a call and the speakers and mic are working as expected.

My problem is that I can't seem to control the volume.

I tried using the following lines of code to find the correct stream, but none of them seem to work.

I tracked the volume command being sent from the phone to the client in the class HeadsetClientStateMachine , line #1822 in the following link: HeadsetClientStateMachine from lolipop

case EVENT_TYPE_VOLUME_CHANGED:
if (event.valueInt == HeadsetClientHalConstants.VOLUME_TYPE_SPK) {
mAudioManager.setStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO, event.valueInt2, AudioManager.FLAG_SHOW_UI);
mVgsFromStack = true;
Log.d(TAG, "EventVolumeChange STREAM_BLUETOOTH_SCO value: " + event.valueInt2);
}

When I change the volume on the phone, I do see the log showing the updated value of the sound, which means that the setStreamVolume() method is being called, but the volume doesn't change.

Does anyone know what could be causing this issue?

EDIT:

I am still looking for an answer and am now looking toward the audio HAL implementation. I suspect that the link between the HAL and the audio driver is somehow incorrect... I don't know much about low level implementation and am not sure what I should be looking for.

5092 次浏览

Could you please try below. I did not try myself but sounds similar problem if I understand correctly:

Android Bluetooth Earpiece Volume

"Android is using int 6 for bluetooth volume and not documented. Just use 6 instead of AudioManager.STREAM_VOICE_CALL and try, It should work"

I assume for you will be to replace AudioManager.STREAM_BLUETOOTH_SCO with 6.

Good luck, I hope it will work.