title: Howto connect to Bluetooth LE Device on Android (Platform 19)
body: <p>I am working with a BT Low Energy capable baggage alert device (<a href="http://www.amazon.de/VisorTech-Mobiler-Bluetooth-Alarm-Smartphones-Bluetooth/dp/B00B4SHD2A" rel="nofollow">Link</a>) and have successfully paired it with my Nexus 7.</p>
  
  <p>Following the <a href="http://developer.android.com/guide/topics/connectivity/bluetooth-le.html" rel="nofollow">docs</a> 
  I now would like to connect to the device using the following code:</p>
  
  <pre><code>private BluetoothGattCallback callback = new BluetoothGattCallback() {
      @Override
      public void onConnectionStateChange(BluetoothGatt gatt, int status,
              int newState) {
          Log.i(TAG, "le onConnectionStateChange ["+newState+"]");
          if (newState == BluetoothProfile.STATE_CONNECTED) {
              Log.i(TAG, "le device connected");
              onConnect(gatt.getDevice());
          } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
              Log.i(TAG, "le device disconnected");
              onDisconnect(gatt.getDevice());
          }
      }
      @Override
      public void onServicesDiscovered (BluetoothGatt gatt, int status) {
          Log.i(TAG, "onServicesDiscovered");
      }
  };
  
  
  for (BluetoothDevice device : BluetoothAdapter.getDefaultAdapter().getBondedDevices()) {
      int type = device.getType();
  
      if (type == BluetoothDevice.DEVICE_TYPE_LE || type == BluetoothDevice.DEVICE_TYPE_DUAL) {
          List&lt;BluetoothDevice&gt; connectedDevices =    
          bluetoothManager.getConnectedDevices(BluetoothProfile.GATT);
  
          if (!connectedDevices.contains(device)) {
              BluetoothGatt gatt = device.connectGatt(App.getContext(), false, callback);
              gatt.connect();
              gatt.discoverServices();
              List&lt;BluetoothGattService&gt; services = gatt.getServices();
          }
      }
  }
  </code></pre>
  
  <p>However no connection can be initiated. After a while (a few seconds) the connection state
  changes to BluetoothProfile.STATE_DISCONNECTED - that is even though BluetoothProfile.STATE_CONNECTED
  was never reached. Am I doing something wrong here? </p>