@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { System.out.println("onServicesDiscoverd(): " + gatt + ", status: " + status); if (gatt != btGatt) return; List<BluetoothGattService> list = btGatt.getServices(); for (BluetoothGattService s : list) { System.err.println( "Found service: " + s.getType() + ", " + s.getInstanceId() + ", " + s.getUuid()); for (BluetoothGattCharacteristic a : s.getCharacteristics()) { System.err.println(" char: " + a.getUuid()); } for (BluetoothGattService a : s.getIncludedServices()) { System.err.println(" serv: " + a.getUuid()); } } System.out.println(" => DummyRead"); if (status == BluetoothGatt.GATT_SUCCESS) { DummyReadForSecLevelCheck(gatt); // continue in onCharacteristicRead } else { DummyReadForSecLevelCheck(gatt); // reportConnectFailed("onServicesDiscovered(" + gatt + ", " + // status + ")"); } }
public JSONObject asJSONObject(BluetoothGatt gatt) { JSONObject json = asJSONObject(); try { JSONArray servicesArray = new JSONArray(); JSONArray characteristicsArray = new JSONArray(); json.put("services", servicesArray); json.put("characteristics", characteristicsArray); if (connected && gatt != null) { for (BluetoothGattService service : gatt.getServices()) { servicesArray.put(UUIDHelper.uuidToString(service.getUuid())); for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) { JSONObject characteristicsJSON = new JSONObject(); characteristicsArray.put(characteristicsJSON); characteristicsJSON.put("service", UUIDHelper.uuidToString(service.getUuid())); characteristicsJSON.put( "characteristic", UUIDHelper.uuidToString(characteristic.getUuid())); // characteristicsJSON.put("instanceId", characteristic.getInstanceId()); characteristicsJSON.put("properties", Helper.decodeProperties(characteristic)); // characteristicsJSON.put("propertiesValue", characteristic.getProperties()); if (characteristic.getPermissions() > 0) { characteristicsJSON.put("permissions", Helper.decodePermissions(characteristic)); // characteristicsJSON.put("permissionsValue", characteristic.getPermissions()); } JSONArray descriptorsArray = new JSONArray(); for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) { JSONObject descriptorJSON = new JSONObject(); descriptorJSON.put("uuid", UUIDHelper.uuidToString(descriptor.getUuid())); descriptorJSON.put("value", descriptor.getValue()); // always blank if (descriptor.getPermissions() > 0) { descriptorJSON.put("permissions", Helper.decodePermissions(descriptor)); // descriptorJSON.put("permissionsValue", descriptor.getPermissions()); } descriptorsArray.put(descriptorJSON); } if (descriptorsArray.length() > 0) { characteristicsJSON.put("descriptors", descriptorsArray); } } } } } catch (JSONException e) { // TODO better error handling e.printStackTrace(); } return json; }
@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { super.onServicesDiscovered(gatt, status); LogTool.d(TAG, "on services discovered success ? " + (status == BluetoothGatt.GATT_SUCCESS)); if (status == BluetoothGatt.GATT_SUCCESS) { displayGattServices(gatt.getServices()); if (gatt.getServices() == null || gatt.getServices().isEmpty()) { LogTool.e(TAG, "No gatt service found!"); onServicesDiscoveredFailed(gatt); return; } if (!checkCloudWatchServiceSupported(gatt)) { LogTool.e(TAG, "Clouder watch services does not support!"); onServicesDiscoveredFailed(gatt); gatt.disconnect(); return; } onServicesDiscoveredSuccess(gatt); } else { LogTool.e(TAG, "Can not found gatt services!"); onServicesDiscoveredFailed(gatt); } }
@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { Log.d("status=" + LogUtil.getConstantName(BluetoothGatt.class, status, "GATT_")); List<BluetoothGattService> services = gatt.getServices(); boolean found = false; for (BluetoothGattService service : services) { Log.d(service.getUuid().toString()); if (getAssignedNumber(service.getUuid()) == GATT_SERVICE_HEART_RATE) { // Found heart rate service onHeartRateServiceFound(service); found = true; break; } } if (!found) { onHeartRateServiceNotFound(); } }
@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED); List<BluetoothGattService> services = gatt.getServices(); for (BluetoothGattService service : services) { List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); for (BluetoothGattCharacteristic characteristic : characteristics) { // setCharacteristicNotification(characteristic, true); } } } else { Log.i(TAG, "onServicesDiscovered received: " + status); } }
@Override public void onServicesDiscovered(final BluetoothGatt gatt, final int status) { // this will get called after the client initiates a // BluetoothGatt.discoverServices() call System.out.println("Services Discovered!"); services = gatt.getServices(); System.out.println("Anzahl Services: " + services.size()); for (int i = 0; i < services.size(); i++) { BluetoothGattService s = services.get(i); if (s.getUuid().equals(UUID_HUM_SERV)) { Message m10 = new Message(10, gatt.getDevice().getAddress()); Message m20 = new Message(20, gatt.getDevice().getAddress()); messageQueue.add(m10); messageQueue.add(m20); } else if (s.getUuid().equals(UUID_ACC_SERV)) { Message m11 = new Message(11, gatt.getDevice().getAddress()); Message m21 = new Message(21, gatt.getDevice().getAddress()); messageQueue.add(m11); messageQueue.add(m21); } else if (s.getUuid().equals(UUID_SENSI_HUM_SERV)) { Message m30 = new Message(30, gatt.getDevice().getAddress()); messageQueue.add(m30); } else if (s.getUuid().equals(UUID_SENSI_TEMP_SERV)) { Message m31 = new Message(31, gatt.getDevice().getAddress()); messageQueue.add(m31); } } /** * This is a self-contained function for turning on the magnetometer sensor. It must be * called AFTER the onServicesDiscovered callback is received. */ if (messageQueue.size() > 0) { Message m = messageQueue.getFirst(); messageQueue.removeFirst(); callFunctionByMessage(m); System.out.println("Activate Function on Services: " + m.getId()); } }
/** * Retrieves a list of supported GATT services on the connected device. This should be invoked * only after {@code BluetoothGatt#discoverServices()} completes successfully. * * @return A {@code List} of supported services. */ public List<BluetoothGattService> getSupportedGattServices() { if (mBluetoothGatt == null) return null; return mBluetoothGatt.getServices(); }
// ---------------------------------------------------------------------------------------------------------------- // Retrieve and return a list of supported GATT services on the connected device public List<BluetoothGattService> getSupportedGattServices() { if (mBluetoothGatt == null) { // Check that we have a valid GATT connection return null; } return mBluetoothGatt.getServices(); // Get the list of services }
@Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { List<BluetoothGattService> services = gatt.getServices(); Log.i("onServicesDiscovered", services.toString()); gatt.readCharacteristic(services.get(1).getCharacteristics().get(0)); }