Detect if bluetooth headset connected

Viewed 8829

Working on a VOIP application, in silent mode an alert tone or ringtone should play on bluetooth headset only. Able to play it on headphone if connected but if the headset is not connected the tone plays on the speaker though the mobile is in silent mode.

Someone please explain if there is a way to detect that a bluetooth headset is connected.

3 Answers

For a simple check, use the following. Remember to add BLUETOOTH permission to your manifest (Non Dangerous permission)

val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
return (bluetoothAdapter != null && BluetoothProfile.STATE_CONNECTED == bluetoothAdapter.getProfileConnectionState(BluetoothProfile.HEADSET))
Related