Android BLE Gatt timeout después de gatt.writeDescriptor ()

Actualmente estoy tratando de obtener una aplicación BLE en el androide para trabajar. En concreto, estoy tratando de captar una señal BLE enviada desde un dispositivo iOS. A continuación se muestra el código relevante para mi problema.

public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { Log.w(tag, "State: " + newState+" status: "+ status + " (0 is success)"); if (newState == BluetoothProfile.STATE_CONNECTED) { String intentAction = "com.example.bluetooth.le.ACTION_GATT_CONNECTED"; final Intent intent = new Intent(intentAction); callbackActivity.sendBroadcast(intent); Log.w(tag, "Connected to GATT server."); // Attempts to discover services after successful connection. Log.w(tag, "Attempting to start service discovery:" + mConnectedGatt.discoverServices()); // Clear data to prepare for new data reading bluetoothData.clear(); } else { Log.w(tag, "GATT connection unsuccessful."); restartSearch(gatt); } } /** * Called when a service has been discovered in the connected device */ @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { Log.w(tag, "Services Discovered! "+status); if(gatt.getService(SERVICE_UUID)!=null){ Log.w(tag, "Not null!"); BluetoothGattCharacteristic characteristic=gatt.getService(SERVICE_UUID).getCharacteristic(CHARACTERISTC_UUID); gatt.setCharacteristicNotification(characteristic, true); BluetoothGattDescriptor descriptor = characteristic.getDescriptor( CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID); descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); Log.w(tag, "Writing to descriptor: "+mConnectedGatt.writeDescriptor(descriptor)); } else{ Log.w(tag, "Services discovered unsuccessful"); restartSearch(gatt); } 

Cuando activo ambos dispositivos, el dispositivo androide siempre recoge la conexión. La conexión siempre es un éxito, y la llamada a discoverServices () siempre da como resultado una devolución de llamada a onServiceDiscovered. La característica que busco se encuentra, y la llamada mConnectedGatt.writeDescriptor (descriptor) siempre devuelve true. Sin embargo, mi devolución de llamada onCharacteristicChanged nunca se llama. En su lugar, el programa espera unos 10 segundos después de la llamada writeDescriptor y, a continuación, recibo una llamada a onConnectionStateChanged especificando que se ha perdido la conexión. Esto sucede el 95% del tiempo. 5% del tiempo, todo funciona perfectamente y recibo la llamada a onCharacteristicChanged.

¿Hay razones para este tiempo de espera que sigue ocurriendo? Como una nota lateral, creo que esto es un problema dentro de mi código Android, como puedo perfectamente enviar y recibir esta señal BLE entre dispositivos iOS.

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.