title: Totally Disconnect a Bluetooth Low Energy Device
body: <p>I connect to a BLE device with the <code>connectGatt()</code> method in Android. This works great.</p>
  
  <p>When I disconnect I use the following:</p>
  
  <pre><code>private void disconnectDevice() {
      gatt.disconnect();
  }
  </code></pre>
  
  <p>When I receive the callback I do a close.</p>
  
  <pre><code>private BluetoothGattCallback gattCallback = new BluetoothGattCallback() {
      @Override
      public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
          switch (newState) {
              case BluetoothProfile.STATE_CONNECTED:
                  Log.d("BLED-GATT", "STATE_CONNECTED");
                  setUIConnectionStatus("Discover services on device...", Color.YELLOW);
                  checkEnableAddButton(simpleTrackEditText.getText().toString());
                  gatt.discoverServices();
                  break;
              case BluetoothProfile.STATE_DISCONNECTED:
                  Log.d("BLED-GATT", "STATE_DISCONNECTED");
                  setUIConnectionStatus("Not Connected!", Color.RED);
                  gatt.close();
                  break;
              default:
                  Log.d("BLED-GATT", "STATE_OTHER");
          }
      }
  }
  </code></pre>
  
  <p>This is executed and I can no longer control the device after calling <code>disconnectDevice()</code>. The device itself seems to think that it is still connected since I cant put it in broadcasting visibility mode (which happens if it already has a connection). However, if I kill the application and open it again then I can set the device in broadcasting mode. This tells me the app was not properly disconnected.</p>
  
  <p>Any idea what I missed here? </p>