From 8202921a6d3c9899544b72f14a6bdd3d51af569c Mon Sep 17 00:00:00 2001 From: Louis-Guillaume DUBOIS Date: Fri, 2 Jun 2017 18:31:40 +0200 Subject: [PATCH] =?UTF-8?q?Enl=C3=A8ve=20les=20boutons=20=C2=AB=20(d=C3=A9?= =?UTF-8?q?)connecter=20=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../students/clientble/BluetoothLeService.java | 9 ++++++++- .../students/clientble/SimpleDetailActivity.java | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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