How can I tell when a Bluetooth device connects to the phone, whether it's A2DP or not?
This tutorial gives a really easy-to-follow guide on listening for Bluetooth connections.
I want to use that to determine if any connected Bluetooth device is an A2DP type.
AudioManager
has a method isBluetoothA2dpOn()
but I don't think this will return true straight away, (or even for certain at all), since just because an A2DP device is connected, that doesn't mean the audio is being routed through it?
I would have thought the information on the type of device connected would be available in the intent received (see tutorial above) but I can't find any documentation on this?
I can get the BluetoothClass
with this code:
BluetoothClass btClass = intent.getParcelableExtra(BluetoothDevice.EXTRA_CLASS);
but that doesn't help me determine if it is an A2DP
profile, since the BluetoothClass
documentation says:
BluetoothClass is useful as a hint to roughly describe a device (for example to show an icon in the UI), but does not reliably describe which Bluetooth profiles or services are actually supported by a device. Accurate service discovery is done through SDP requests, which are automatically performed when creating an RFCOMM socket with createRfcommSocketToServiceRecord(UUID) and listenUsingRfcommWithServiceRecord(String, UUID)
...which is pretty meaningless to me.