title: How to get connection states for a bluetooth low energy device in android
body: <p>Follwoing is the code android uses to get the connection summary(to display the connection status labels)</p>
  
  <pre><code>      private int getConnectionSummary() {
        ...........................
        ...........................
        for (LocalBluetoothProfile profile : cachedDevice.getProfiles()) {
              int connectionStatus = cachedDevice.getProfileConnectionState(profile);
  
              switch (connectionStatus) {
                  case BluetoothProfile.STATE_CONNECTING:
                  case BluetoothProfile.STATE_DISCONNECTING:
                      return Utils.getConnectionStateSummary(connectionStatus);
  
                  case BluetoothProfile.STATE_CONNECTED:
                      profileConnected = true;
                      break;
  
                  case BluetoothProfile.STATE_DISCONNECTED:
                      if (profile.isProfileReady()) {
                          if (profile instanceof A2dpProfile) {
                              a2dpNotConnected = true;
                          } else if (profile instanceof HeadsetProfile) {
                              headsetNotConnected = true;
                          }
                      }
                      break;
              }
          }
  </code></pre>
  
  <p>As you can see from the code above, they obtain the connection status for a Classic device using the following line of code:</p>
  
  <pre><code>int connectionStatus = cachedDevice.getProfileConnectionState(profile);
  </code></pre>
  
  <p>The android system calls the <code>getConnectionSummary()</code> method irrespective of whether a Classic or Bluetooth Low energy device is trying to connect; but unlike a classic device, since we do not have a method by which we can get the connectionStatus for a bluetooth Low energy device, we are unable to update the connection status correctly for a Low energy device.</p>
  
  <p>Full source for this class can be found <a href="http://source-android.frandroid.com/packages/apps/Settings/src/com/android/settings/bluetooth/BluetoothDevicePreference.java" rel="nofollow">here</a></p>
  
  <p>Any help is much appreciated.</p>