diff --git a/Application/src/main/java/fr/centralesupelec/students/clientble/BluetoothLeService.java b/Application/src/main/java/fr/centralesupelec/students/clientble/BluetoothLeService.java index 3ce0eac..714f2e3 100644 --- a/Application/src/main/java/fr/centralesupelec/students/clientble/BluetoothLeService.java +++ b/Application/src/main/java/fr/centralesupelec/students/clientble/BluetoothLeService.java @@ -37,6 +37,8 @@ import java.util.List; import java.util.StringTokenizer; import java.util.UUID; +import static java.lang.Thread.sleep; + /** * Service for managing connection and data communication with a GATT server hosted on a * given Bluetooth LE device. @@ -318,7 +320,12 @@ public class BluetoothLeService extends Service { enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE ); - while (!mBluetoothGatt.writeDescriptor(descriptor)) ; + try { + while (!mBluetoothGatt.writeDescriptor(descriptor)) + sleep(500); + } catch (Exception e) { + e.printStackTrace(); + } } mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); } diff --git a/Application/src/main/java/fr/centralesupelec/students/clientble/SimpleDetailActivity.java b/Application/src/main/java/fr/centralesupelec/students/clientble/SimpleDetailActivity.java index 5b4d1d7..58c4528 100644 --- a/Application/src/main/java/fr/centralesupelec/students/clientble/SimpleDetailActivity.java +++ b/Application/src/main/java/fr/centralesupelec/students/clientble/SimpleDetailActivity.java @@ -144,6 +144,7 @@ public class SimpleDetailActivity extends Activity { mBluetoothLeService = null; } + /* @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.gatt_services, menu); @@ -156,16 +157,19 @@ public class SimpleDetailActivity extends Activity { } return true; } + */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { + /* case R.id.menu_connect: mBluetoothLeService.connect(mDeviceAddress); return true; case R.id.menu_disconnect: mBluetoothLeService.disconnect(); return true; + */ case android.R.id.home: onBackPressed(); return true; @@ -173,6 +177,7 @@ public class SimpleDetailActivity extends Activity { return super.onOptionsItemSelected(item); } + private void updateConnectionState(final int resourceId) { runOnUiThread(new Runnable() { @Override