Example usage for android.bluetooth BluetoothGattCharacteristic getUuid

List of usage examples for android.bluetooth BluetoothGattCharacteristic getUuid

Introduction

In this page you can find the example usage for android.bluetooth BluetoothGattCharacteristic getUuid.

Prototype

public UUID getUuid() 

Source Link

Document

Returns the UUID of this characteristic

Usage

From source file:com.vehicle.uart.UartService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // 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 (TX_CHAR_UUID.equals(characteristic.getUuid())) {

        intent.putExtra(EXTRA_DATA, characteristic.getValue());
    } else {/*from   w ww  .  ja  v  a 2 s .  com*/

    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}

From source file:com.shenqu.jlplayer.nRFUARTv2.UartService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // 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 (TX_CHAR_UUID.equals(characteristic.getUuid())) {
        // Log.d(TAG, String.format("Received TX: %d",characteristic.getValue() ));
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
    }/* ww  w. j a v  a2 s . com*/
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}

From source file:com.google.android.apps.forscience.ble.MyBleService.java

private void sendGattBroadcast(String address, String gattAction, BluetoothGattCharacteristic characteristic) {
    if (DEBUG)/*from w ww .  jav  a2  s  . c  o  m*/
        Log.d(TAG, "Sending the action: " + gattAction);
    Intent newIntent = BleEvents.createIntent(gattAction, address);
    if (characteristic != null) {
        newIntent.putExtra(UUID, characteristic.getUuid().toString());
        newIntent.putExtra(FLAGS, characteristic.getProperties());
        newIntent.putExtra(DATA, characteristic.getValue());
    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(newIntent);
}

From source file:com.cardiograph.service.UartService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // 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 (TX_CHAR_UUID.equals(characteristic.getUuid())) {

        // Log.d(TAG, String.format("Received TX: %d",characteristic.getValue() ));
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
    } else {//from   w w  w  . jav  a  2  s  .  c o m

    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}

From source file:com.example.alexanderbolinsky.ble_uart_remote.UartService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // 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 (TX_CHAR_UUID.equals(characteristic.getUuid())) {

        // Log.d(TAG, String.format("Received TX: %d",characteristic.getValue() ));
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
    } else {//  w w w .  ja  va  2s. com

    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}

From source file:com.megster.cordova.ble.central.Peripheral.java

private BluetoothGattCharacteristic findNotifyCharacteristic(BluetoothGattService service,
        UUID characteristicUUID) {
    BluetoothGattCharacteristic characteristic = null;

    // Check for Notify first
    List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
    for (BluetoothGattCharacteristic c : characteristics) {
        if ((c.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0
                && characteristicUUID.equals(c.getUuid())) {
            characteristic = c;/* www  .  j a  v a 2  s.  c  om*/
            break;
        }
    }

    if (characteristic != null)
        return characteristic;

    // If there wasn't Notify Characteristic, check for Indicate
    for (BluetoothGattCharacteristic c : characteristics) {
        if ((c.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0
                && characteristicUUID.equals(c.getUuid())) {
            characteristic = c;
            break;
        }
    }

    // As a last resort, try and find ANY characteristic with this UUID, even if it doesn't have the correct properties
    if (characteristic == null) {
        characteristic = service.getCharacteristic(characteristicUUID);
    }

    return characteristic;
}

From source file:com.example.UART.UartService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // 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 (TX_CHAR_UUID.equals(characteristic.getUuid())) {
        // Log.d(TAG, String.format("Received TX: %d",characteristic.getValue() ));
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
    } else {// w  w w.j  av  a  2 s.  com

    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}

From source file:com.ble.BLService.java

/**
 * Enables or disables notification on a give characteristic.
 * //from   w ww .  j  a v a 2  s .  c om
 * @param characteristic
 *            Characteristic to act on.
 * @param enabled
 *            If true, enable notification. False otherwise.
 */
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

    if (UUID_STM32_ACCELEROMETER_PARAMETER.equals(characteristic.getUuid())) {
        BluetoothGattDescriptor descriptor = characteristic
                .getDescriptor(UUID.fromString(BLGattAttributes.STM32_ACCELEROMETER_PARAMETER));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
    }

    if (UUID_STM32_WRITE_TO_DEVICE.equals(characteristic.getUuid())) {
        BluetoothGattDescriptor descriptor = characteristic
                .getDescriptor(UUID.fromString(BLGattAttributes.STM32_WRITE_TO_DEVICE));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
    }

}

From source file:com.aprilbrother.blueduino.UartService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    final Intent intent = new Intent(action);

    // 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 (TX_CHAR_UUID.equals(characteristic.getUuid())) {
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
    } else {//from  w  w  w.j  av  a 2  s  .com

    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.no1f1.No1F1Support.java

@Override
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    if (super.onCharacteristicChanged(gatt, characteristic)) {
        return true;
    }/*w ww  . j  av  a  2 s . c o  m*/

    UUID characteristicUUID = characteristic.getUuid();
    byte[] data = characteristic.getValue();
    if (data.length == 0)
        return true;

    switch (data[0]) {
    case No1F1Constants.CMD_FIRMWARE_VERSION:
        versionCmd.fwVersion = new String(Arrays.copyOfRange(data, 1, data.length));
        handleGBDeviceEvent(versionCmd);
        LOG.info("Firmware version is: " + versionCmd.fwVersion);
        return true;
    case No1F1Constants.CMD_BATTERY:
        batteryCmd.level = data[1];
        handleGBDeviceEvent(batteryCmd);
        LOG.info("Battery level is: " + data[1]);
        return true;
    case No1F1Constants.CMD_DATETIME:
        LOG.info("Time is set to: " + (data[1] * 256 + ((int) data[2] & 0xff)) + "-" + data[3] + "-" + data[4]
                + " " + data[5] + ":" + data[6] + ":" + data[7]);
        return true;
    case No1F1Constants.CMD_USER_DATA:
        LOG.info("User data updated");
        return true;
    case No1F1Constants.CMD_FETCH_STEPS:
    case No1F1Constants.CMD_FETCH_SLEEP:
    case No1F1Constants.CMD_FETCH_HEARTRATE:
        handleActivityData(data);
        return true;
    case No1F1Constants.CMD_REALTIME_HEARTRATE:
        handleRealtimeHeartRateData(data);
        return true;
    case No1F1Constants.CMD_NOTIFICATION:
    case No1F1Constants.CMD_ICON:
    case No1F1Constants.CMD_DEVICE_SETTINGS:
    case No1F1Constants.CMD_DISPLAY_SETTINGS:
        return true;
    default:
        LOG.warn("Unhandled characteristic change: " + characteristicUUID + " code: " + Arrays.toString(data));
        return true;
    }
}