From 69312b83ad4ee107fa55a1768e45d7ddbce8bb70 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Wed, 4 Jul 2018 13:10:24 +0200 Subject: [PATCH] Log exception for #159 --- .../bluetooth/BluetoothCommunication.java | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java index b0fcf43c..29faecf0 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java @@ -290,16 +290,21 @@ public abstract class BluetoothCommunication { protected void setIndicationOn(UUID service, UUID characteristic, UUID descriptor) { Timber.d("Set indication on for %s", characteristic); - BluetoothGattCharacteristic gattCharacteristic = - bluetoothGatt.getService(service).getCharacteristic(characteristic); - bluetoothGatt.setCharacteristicNotification(gattCharacteristic, true); + try { + BluetoothGattCharacteristic gattCharacteristic = + bluetoothGatt.getService(service).getCharacteristic(characteristic); + bluetoothGatt.setCharacteristicNotification(gattCharacteristic, true); - synchronized (lock) { - descriptorRequestQueue.add( - new GattObjectValue<>( - gattCharacteristic.getDescriptor(descriptor), - BluetoothGattDescriptor.ENABLE_INDICATION_VALUE)); - handleRequests(); + synchronized (lock) { + descriptorRequestQueue.add( + new GattObjectValue<>( + gattCharacteristic.getDescriptor(descriptor), + BluetoothGattDescriptor.ENABLE_INDICATION_VALUE)); + handleRequests(); + } + } + catch (Exception e) { + Timber.e(e); } } @@ -312,16 +317,21 @@ public abstract class BluetoothCommunication { protected void setNotificationOn(UUID service, UUID characteristic, UUID descriptor) { Timber.d("Set notification on for %s", characteristic); - BluetoothGattCharacteristic gattCharacteristic = - bluetoothGatt.getService(service).getCharacteristic(characteristic); - bluetoothGatt.setCharacteristicNotification(gattCharacteristic, true); + try { + BluetoothGattCharacteristic gattCharacteristic = + bluetoothGatt.getService(service).getCharacteristic(characteristic); + bluetoothGatt.setCharacteristicNotification(gattCharacteristic, true); - synchronized (lock) { - descriptorRequestQueue.add( - new GattObjectValue<>( - gattCharacteristic.getDescriptor(descriptor), - BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)); - handleRequests(); + synchronized (lock) { + descriptorRequestQueue.add( + new GattObjectValue<>( + gattCharacteristic.getDescriptor(descriptor), + BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)); + handleRequests(); + } + } + catch (Exception e) { + Timber.e(e); } }