Enlève les boutons « (dé)connecter »

This commit is contained in:
Louis-Guillaume DUBOIS 2017-06-02 18:31:40 +02:00
parent b5d22d7b4d
commit 8202921a6d
No known key found for this signature in database
GPG key ID: 96472D986598B31E
2 changed files with 13 additions and 1 deletions

View file

@ -37,6 +37,8 @@ import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.UUID; import java.util.UUID;
import static java.lang.Thread.sleep;
/** /**
* Service for managing connection and data communication with a GATT server hosted on a * Service for managing connection and data communication with a GATT server hosted on a
* given Bluetooth LE device. * given Bluetooth LE device.
@ -318,7 +320,12 @@ public class BluetoothLeService extends Service {
enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
: BluetoothGattDescriptor.DISABLE_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); mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
} }

View file

@ -144,6 +144,7 @@ public class SimpleDetailActivity extends Activity {
mBluetoothLeService = null; mBluetoothLeService = null;
} }
/*
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.gatt_services, menu); getMenuInflater().inflate(R.menu.gatt_services, menu);
@ -156,16 +157,19 @@ public class SimpleDetailActivity extends Activity {
} }
return true; return true;
} }
*/
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) { switch(item.getItemId()) {
/*
case R.id.menu_connect: case R.id.menu_connect:
mBluetoothLeService.connect(mDeviceAddress); mBluetoothLeService.connect(mDeviceAddress);
return true; return true;
case R.id.menu_disconnect: case R.id.menu_disconnect:
mBluetoothLeService.disconnect(); mBluetoothLeService.disconnect();
return true; return true;
*/
case android.R.id.home: case android.R.id.home:
onBackPressed(); onBackPressed();
return true; return true;
@ -173,6 +177,7 @@ public class SimpleDetailActivity extends Activity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void updateConnectionState(final int resourceId) { private void updateConnectionState(final int resourceId) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override