Hello.
After connection establishing i would like to doscover services.
I read here:
that need to add 600ms delay before "gatt.discoverServices();"
private final BluetoothGattCallback gattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); Log.d("Connection", newState+""); Toast.makeText(context, newState+"", Toast.LENGTH_SHORT).show(); //Here is the place for 600ms delay try { Thread.sleep(600); } catch (InterruptedException e) { e.printStackTrace(); } gatt.discoverServices(); } @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { super.onServicesDiscovered(gatt, status); List <BluetoothGattService> services = gatt.getServices(); Log.d("services","Services "); //gatt.readCharacteristic(services.get(1).getCharacteristics().get(0)); } @Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { super.onCharacteristicRead(gatt, characteristic, status); //Log.d("czy_polaczono", "Charakterystyki: " +characteristic.toString()); } @Override public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { super.onCharacteristicWrite(gatt, characteristic, status); } @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { super.onCharacteristicChanged(gatt, characteristic); // Log.d("czy_polaczono", "Charakterystyki: " +characteristic.toString()); } };
I tried with and without delay but it did not work. Does anybody have a knowledge how to fix this?