4

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.

Jodes
  • 14,118
  • 26
  • 97
  • 156
  • 2
    IIRC, `isBluetoothA2dpOn` will return `true` if an A2DP device is _available_ from the audio HAL's point of view (connected and paired). There doesn't necessarily have to be any audio routed to the A2DP device. – Michael Aug 22 '14 at 10:25
  • Very interesting, thank you. I would like to be certain about that though, it's a shame documentation is so sparse. – Jodes Aug 22 '14 at 10:28

0 Answers0