title: Android Intent: detect when Bluetooth A2DP device gets connected (Not whether a2dp routing is active)
body: <p>How can I tell when a Bluetooth device connects to the phone, whether it's A2DP or not?</p>
  
  <p><a href="http://b2cloud.com.au/tutorial/listening-to-bluetooth-connections/" rel="nofollow">This tutorial</a> gives a really easy-to-follow guide on listening for Bluetooth connections. </p>
  
  <p>I want to use that to determine if any connected Bluetooth device is an A2DP type.</p>
  
  <p><a href="http://developer.android.com/reference/android/media/AudioManager.html" rel="nofollow"><code>AudioManager</code></a> has a method <code>isBluetoothA2dpOn()</code> 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?</p>
  
  <p>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?</p>
  
  <p>I can get the <code>BluetoothClass</code> with this code:</p>
  
  <pre><code>BluetoothClass btClass = intent.getParcelableExtra(BluetoothDevice.EXTRA_CLASS);
  </code></pre>
  
  <p>but that doesn't help me determine if it is an <code>A2DP</code> profile, since the <code>BluetoothClass</code> documentation says:</p>
  
  <blockquote>
    <p>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)</p>
  </blockquote>
  
  <p>...which is pretty meaningless to me.</p>