title: Can not discover Service and Characteristics via Bluetooth Low Energy - BLE
body: <p>I am working on Bluetooth Low Energy - BLE.</p>
  
  <p>I can scan and find out, connect to firmware devices via Bluetooth by using BLE.</p>
  
  <p><code>mBluetoothGatt = mAl.get(pos).connectGatt(mContext, false, mGattCallback);</code></p>
  
  <p>While app from Play store can discover <code>Services</code> and <code>Characteristics</code> inside firmware device, my android application can not discover them, it always return empty services list. Actually Firmware device already set up <code>Services</code> and <code>Characteristics</code> also.</p>
  
  <p>I don't know why, who know why, please help me how to discover <code>Services</code> and <code>Characteristics</code>,</p>
  
  <p>Thank you,</p>
  
  <p><strong>Java code</strong></p>
  
  <pre><code>// Various callback methods defined by the BLE API.
      private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
          @Override
          public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
              if (newState == BluetoothProfile.STATE_CONNECTED) {
                  /**
                   * In case already connected to Pas device
                   */
                  Log.i("", "Connected to GATT server. " + gatt.discoverServices());
                  // CALL THIS METHOD TO BEGIN DISCOVER SERVICES
                  gatt.discoverServices();
  
              } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                  /**
                   * In case disconnected Pas device
                   */
                  Log.i("", "Disconnected from GATT server.");
              }
          }
  
          @Override
          // New services discovered
          public void onServicesDiscovered(BluetoothGatt gatt, int status) {
              Log.i("", "onServicesDiscovered " + status + " " + gatt.discoverServices()
                      + " " + gatt.getServices());
  
              // RETURN : []
              Log.i("", "gatt.getServices() " + gatt.getServices());
              // RETURN : TRUE
              Log.i("", "gatt.getServices() " + gatt.getServices().isEmpty());
  
              // EXCEPTION HAPPEN BCS SIZE = 0
              gatt.readCharacteristic(gatt.getServices().get(0).getCharacteristics().get(0));
  
              if (status == BluetoothGatt.GATT_SUCCESS) {
              } else {
                  Log.w("", "onServicesDiscovered received: " + status);
              }
          }
  
          @Override
          // Result of a characteristic read operation
          public void onCharacteristicRead(
                  BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
                  int status) {
              Log.i("", "onCharacteristicRead " + status + " " + characteristic);
  
              if (status == BluetoothGatt.GATT_SUCCESS) {
              }
          }
      };
  
  // Device scan callback.
          private BluetoothAdapter.LeScanCallback mLeScanCallback =
                  new BluetoothAdapter.LeScanCallback() {
                      @Override
                      public void onLeScan(final BluetoothDevice device, int rssi,
                                           byte[] scanRecord) {
                          getActivity().runOnUiThread(new Runnable() {
                              @Override
                              public void run() {
                                  /**
                                   * Should show Scan Pas Devices :
                                   * Add to array list scanned pas devices if it is not exist in list
                                   * before
                                   */
                                  if (!mAlPasDeviceNames.contains(device.getName())) {
                                      mAlPasDevices.add(device);
                                      mAlPasDeviceNames.add(device.getName());
  
                                      // set adapter and show on UI
                                      mLv.setAdapter(new PasConnectionAdapter(
                                              getActivity(),
                                              R.layout.simple_list_item_scan_pas_device,
                                              mAlPasDevices));
                                  }
                              }
                          });
                      }
                  };
  </code></pre>
  
  <p><strong>Logcat</strong></p>
  
  <pre><code>connect() - device: E2:5A:6B:5A:18:57, auto: false
  D/BluetoothGatt: registerApp()
  D/BluetoothGatt: registerApp() - UUID=93455863-c385-4563-9197-6592024cc8cc
  D/BtGatt.GattService: registerClient() - UUID=93455863-c385-4563-9197-6592024cc8cc
  D/BtGatt.GattService: onClientRegistered() - UUID=93455863-c385-4563-9197-6592024cc8cc, clientIf=5
  D/BluetoothGatt: onClientRegistered() - status=0 clientIf=5
  D/BtGatt.GattService: clientConnect() - address=E2:5A:6B:5A:18:57, isDirect=true
  E/BluetoothRemoteDevices: aclStateChangeCallback: Device is NULL
  D/BtGatt.GattService: onConnected() - clientIf=5, connId=5, address=E2:5A:6B:5A:18:57
  D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=E2:5A:6B:5A:18:57
  D/BluetoothGatt: discoverServices() - device: E2:5A:6B:5A:18:57
  D/BtGatt.GattService: discoverServices() - address=E2:5A:6B:5A:18:57, connId=5
  I/: Connected to GATT server. true
  D/BluetoothGatt: discoverServices() - device: E2:5A:6B:5A:18:57
  D/BtGatt.GattService: discoverServices() - address=E2:5A:6B:5A:18:57, connId=5
  D/BtGatt.GattService: onSearchCompleted() - connId=5, status=0
  D/BtGatt.GattService: onSearchCompleted() - connId=5, status=0
  E/BtGatt.btif: bta_to_btif_uuid: Unknown UUID length 61618!
  E/BtGatt.btif: bta_to_btif_uuid: Unknown UUID length 61619!
  I/: gatt.getService(uuid) null
  D/BluetoothGatt: onSearchComplete() = Device=E2:5A:6B:5A:18:57 Status=0
  D/BluetoothGatt: discoverServices() - device: E2:5A:6B:5A:18:57
  D/BtGatt.GattService: discoverServices() - address=E2:5A:6B:5A:18:57, connId=5
  D/BtGatt.GattService: onSearchCompleted() - connId=5, status=0
  I/: onServicesDiscovered 0 true []
  I/: gatt.getServices() []
  I/: gatt.getServices() true
  E/BtGatt.btif: bta_to_btif_uuid: Unknown UUID length 61621!
  W/BluetoothGatt: Unhandled exception in callback
  W/BluetoothGatt: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
  W/BluetoothGatt:     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
  W/BluetoothGatt:     at java.util.ArrayList.get(ArrayList.java:308)
  W/BluetoothGatt:     at ui.fragment.PasConnectionFragment$1.onServicesDiscovered(PasConnectionFragment.java:379)
  W/BluetoothGatt:     at android.bluetooth.BluetoothGatt$1.onSearchComplete(BluetoothGatt.java:304)
  W/BluetoothGatt:     at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:217)
  W/BluetoothGatt:     at android.os.Binder.execTransact(Binder.java:446)
  </code></pre>