Android 4.3 Bluetooth ble no se llama onCharacteristicRead ()

He fijado la notificación en androide, no está llamando al método onCharacteristicRead() ???? No entra en la función. ¿Por qué está sucediendo así ??

Cualquier ayuda es apreciada

Solicite las soluciones.

Este es mi código:

 private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { if (newState == BluetoothProfile.STATE_CONNECTED) { Log.i(TAG, "Connected to GATT server."); // Attempts to discover services after successful connection. Log.i(TAG, "Attempting to start service discovery:" + mBluetoothGatt.discoverServices()); } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { Log.i(TAG, "Disconnected from GATT server."); } } @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { gattServices = mBluetoothGatt .getService(SampleGattAttributes.SERVICES_UUID); if (gattServices != null) { gattCharacteristics = gattServices .getCharacteristic(SampleGattAttributes.CHARACTERISTIC_UUID); System.out.println("character-->" + gattCharacteristics); } if (gattCharacteristics != null) { System.out.println("Characteristic not null"); System.out.println("Characteristic Properties-->" + gattCharacteristics.getProperties()); mBluetoothGatt.setCharacteristicNotification(gattCharacteristics, true); } } else { Log.w(TAG, "onServicesDiscovered received: " + status); } } @Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { System.out.println("in read"); if (status == BluetoothGatt.GATT_SUCCESS) { byte[] data = characteristic.getValue(); System.out.println("reading"); System.out.println(new String(data)); } } @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { // System.out.println("change"); byte[] data = characteristic.getValue(); System.out.println(new String(data)); } }; 

¡¡Gracias de antemano!!

En primer lugar, onCharacteristicRead se disparará si ha leído una característica mediante:

  mBluetoothGatt.readCharacteristic(characteristic); 

Leer una característica y configurar notificaciones son dos cosas diferentes. ¿Cuál es el tipo de característica que desea obtener los datos?

Lo es:

  • leer
  • notificar
  • indicar

Si se read , puede leer la característica usando el mBluetoothGatt.readCharacteristic(characteristic); pero si su notify o indicate primero tendrá que leer el descriptor la característica llamando a:

 mBluetoothGatt.readDescriptor(ccc); 

Una vez que lo lea, debe devolver datos llamando a la onDescriptorRead llamada onDescriptorRead .
Aquí puede configurar (suscribirse) a la caracteres mediante una notificación o una indicación llamando a:

 mBluetoothGatt.setCharacteristicNotification(characteristic, true) 

una vez que devuelve true , tendrá que volver a escribir en el descriptor (el valor de notificación o indicación)

 BluetoothGattDescriptor clientConfig = characteristic.getDescriptor(CCC); clientConfig.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); // or //clientConfig.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); mBluetoothGatt.writeDescriptor(clientConfig); 

Una vez hecho esto, obtendrá notificaciones a través de la onCharacteristicChanged devolución de onCharacteristicChanged cada vez que cambie la característica.

puedes leer más acerca de la conexión Bluetooth en Android aquí
y acerca de las características de Bluetooth aquí

  • Interfaz de deserialización de Gson para su implementación Class
  • ¿Cuál es el orden correcto de llamar métodos de superclase en los métodos onPause, onStop y onDestroy? ¿y por qué?
  • Formato de doble Android
  • Establecer el enfoque a un botón
  • Android.provider.Settings.Secure.ANDROID_ID devuelve "android_id"
  • Error Cursor.moveToNext
  • Cómo crear un archivo jar desde android studio
  • Cambiar Google Place Picker Appbar Text Color
  • Fuentes personalizadas y diseños XML (Android)
  • Java: Eficaz ArrayList filtrado?
  • Cómo agregar un proyecto para crear ruta de acceso en IntelliJ Idea
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.