List of usage examples for android.bluetooth BluetoothGattCharacteristic getService
public BluetoothGattService getService()
From source file:com.megster.cordova.ble.central.Peripheral.java
private String generateHashKey(BluetoothGattCharacteristic characteristic) { return generateHashKey(characteristic.getService().getUuid(), characteristic); }
From source file:is.hello.buruberi.bluetooth.stacks.android.NativeGattPeripheral.java
@Override public void onCharacteristicChanged(@NonNull BluetoothGatt gatt, @NonNull BluetoothGattCharacteristic characteristic) { if (gatt == this.gatt) { final UUID serviceId = characteristic.getService().getUuid(); final NativeGattService gattService = services.get(serviceId); gattService.dispatchNotify(characteristic.getUuid(), characteristic.getValue()); }/*www . j av a 2s . c om*/ }
From source file:com.nbplus.iotapp.bluetooth.BluetoothLeService.java
private void broadcastUpdate(final String address, final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); intent.putExtra(EXTRA_DATA_SERVICE_UUID, characteristic.getService().getUuid().toString()); intent.putExtra(EXTRA_DATA_CHARACTERISTIC_UUID, characteristic.getUuid().toString()); String str = ""; byte[] values = characteristic.getValue(); Log.d(TAG,/*from www . ja v a 2s . c o m*/ "onCharacteristicChanged: address : " + address + ", uuid:" + characteristic.getUuid().toString()); // This is special handling for the Heart Rate Measurement profile. Data parsing is // carried out as per profile specifications: // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { int flag = characteristic.getProperties(); int format = -1; if ((flag & 0x01) != 0) { format = BluetoothGattCharacteristic.FORMAT_UINT16; Log.d(TAG, "Heart rate format UINT16."); } else { format = BluetoothGattCharacteristic.FORMAT_UINT8; Log.d(TAG, "Heart rate format UINT8."); } final int heartRate = characteristic.getIntValue(format, 1); Log.d(TAG, String.format("Received heart rate: %d", heartRate)); intent.putExtra(EXTRA_DATA, values); } else if (UUID_WEIGHT_MEASUREMENT.equals(characteristic.getUuid())) { // for weight scale int flag = values[0] & 0xff; Log.w(TAG, String.format("Measurement data received flag = %02x", flag)); /** * ? reserved field ? 2? ? ??. */ if (address != null && address.startsWith(GattAttributes.XIAOMI_MAC_ADDRESS_FILTER)) { if (values == null || values.length <= 0 || (values[0] & 0xf0) != 0x20) { Log.d(TAG, "ignore ... flag 4nibble 0x20 is not ... "); return; } } ArrayList<WeightMeasurement> measurements = WeightMeasurement.parseWeightMeasurement(address, characteristic.getUuid().toString(), values); intent.putParcelableArrayListExtra(EXTRA_DATA, measurements); } else if (UUID_GLUCOSE_MEASUREMENT.equals(characteristic.getUuid())) { GlucoseMeasurement measurement = GlucoseMeasurement.parseGlucoseMeasurement(values); intent.putExtra(EXTRA_DATA, measurement); } else if (UUID_GLUCOSE_MEASUREMENT_CONTEXT.equals(characteristic.getUuid())) { } else if (UUID_RECORD_ACCESS_CONTROL_POINT.equals(characteristic.getUuid())) { RecordAccessControlPoint recordAccessControlPoint = RecordAccessControlPoint .parseRecordAccessControlPoint(values); intent.putExtra(EXTRA_DATA, recordAccessControlPoint); } else if (UUID.fromString(GattAttributes.CURRENT_TIME).equals(characteristic.getUuid())) { if (values != null && values.length > 0) { intent.putExtra(EXTRA_DATA, values); } //intent.putExtra(EXTRA_DATA, characteristic.getValue()); } else { // For all other profiles, writes the data formatted in HEX. if (values != null && values.length > 0) { intent.putExtra(EXTRA_DATA, values); } } sendBroadcast(intent); }