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.example.kevin.health.ble.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 (HR_CHAR_UUID.equals(characteristic.getUuid())) {

        // Log.d(TAG, String.format("Received HR: %d",characteristic.getValue() ));
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
    } else if (HR_CHAR_UUID.equals(characteristic.getUuid())) {
        // Log.d(TAG, String.format("Received Tx: %d",characteristic.getValue() ));
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
    } else if (TX_CHAR_UUID.equals(characteristic.getUuid())) {
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
    } else {//from w  w w  .j a  v a2  s . c o  m

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

From source file:com.sdingba.su.alphabet_demotest.view.lanya.UartService.java

/**
 * ??/*ww w . j  a  va  2  s. com*/
 * @param action
 */
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 {

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

From source file:com.ucai.test.control.DeviceControlActivity.java

/**
 * ???GATT?/?/*from   www.  ja  va2s .  c  om*/
 * ,?ExpandableListViewUI
 *
 * @param gattServices
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void displayGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null)
        return;
    String uuid = null;
    String unknownServiceString = getResources().getString(R.string.unknown_service);
    String unknownCharaString = getResources().getString(R.string.unknown_characteristic);
    ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>();
    ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData = new ArrayList<ArrayList<HashMap<String, String>>>();
    mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>();

    // Loops through available GATT Services.
    //???GATT?
    for (BluetoothGattService gattService : gattServices) {
        HashMap<String, String> currentServiceData = new HashMap<String, String>();
        uuid = gattService.getUuid().toString();
        currentServiceData.put(LIST_NAME, SampleGattAttributes.lookup(uuid, unknownServiceString));
        currentServiceData.put(LIST_UUID, uuid);
        gattServiceData.add(currentServiceData);

        ArrayList<HashMap<String, String>> gattCharacteristicGroupData = new ArrayList<HashMap<String, String>>();
        List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
        ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>();
        //Log.e("/g", "" + uuid);
        // Loops through available Characteristics.
        //???
        for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
            charas.add(gattCharacteristic);
            HashMap<String, String> currentCharaData = new HashMap<String, String>();
            uuid = gattCharacteristic.getUuid().toString();
            currentCharaData.put(LIST_NAME, SampleGattAttributes.lookup(uuid, unknownCharaString));
            currentCharaData.put(LIST_UUID, uuid);
            gattCharacteristicGroupData.add(currentCharaData);
            //TODO ?uuid
            Log.e("/t", "" + uuid);
        }
        mGattCharacteristics.add(charas);
        gattCharacteristicData.add(gattCharacteristicGroupData);
        Log.e("cst", "load over");
    }

    /*SimpleExpandableListAdapter gattServiceAdapter = new SimpleExpandableListAdapter(
        this,
        gattServiceData,
        android.R.layout.simple_expandable_list_item_2,
        new String[]{LIST_NAME, LIST_UUID},
        new int[]{android.R.id.text1, android.R.id.text2},
        gattCharacteristicData,
        android.R.layout.simple_expandable_list_item_2,
        new String[]{LIST_NAME, LIST_UUID},
        new int[]{android.R.id.text1, android.R.id.text2}
            
    );
    mGattServicesList.setAdapter(gattServiceAdapter);*/
}

From source file:com.sdingba.su.lanya.UartService.java

/**
 * ??/*from w w w  . jav a2  s. c o  m*/
 *
 * @param action
 */
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())) {
        //?TXCC254x???0xfff4notify?
        Log.d(TAG, String.format("Received TX: %d", characteristic.getValue()));
        Log.w(TAG, "SDingBaLanYan characteristic.getUuid() = " + characteristic.getUuid());
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
    } else {

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

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

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic,
        byte[] myValue) {
    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, myValue);
    } else {//from www  . j a  v a  2  s.  c  o  m

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

From source file:com.example.android.bluetoothlegatt.DeviceControlActivity.java

private boolean bluetoothLookup(BluetoothGattService gattService, String readCharacteristicUuid,
        String writeCharacteristicUuid, String notifyCharacteristicUuid) {
    for (BluetoothGattCharacteristic characteristic : gattService.getCharacteristics()) {
        final String uuid = characteristic.getUuid().toString();
        Log.d(TAG,//from   ww w. j av  a2  s .co m
                "characteristic " + uuid.substring(4, 8) + ": " + Util.isCharacteristicReadable(characteristic)
                        + " " + Util.isCharacteristicWritable(characteristic) + " "
                        + Util.isCharacteristicNotifiable(characteristic));

        if (uuid.toString().equalsIgnoreCase(readCharacteristicUuid)
                && Util.isCharacteristicReadable(characteristic)) {
            Log.d(TAG, "Setup characteristic read " + uuid.substring(4, 8));
            mReadCharacteristic = characteristic;
            // If there is an active notification on a characteristic, clear
            // it first so it doesn't update the data field on the user interface.
            if (mNotifyCharacteristic != null) {
                mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, false);
                mNotifyCharacteristic = null;
            }
        }
        if (uuid.toString().equalsIgnoreCase((writeCharacteristicUuid))
                && Util.isCharacteristicWritable(characteristic)) {
            Log.d(TAG, "Setup characteristic write " + uuid.substring(4, 8));
            mWriteCharacteristic = characteristic;
        }
        if (uuid.toString().equalsIgnoreCase(notifyCharacteristicUuid)
                && Util.isCharacteristicNotifiable(characteristic)) {
            Log.d(TAG, "Setup characteristic notify " + uuid.substring(4, 8));
            mNotifyCharacteristic = characteristic;
            mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, true);
        }
    }
    return (mReadCharacteristic != null && mWriteCharacteristic != null);
}

From source file:com.qi.airstat.BluetoothLeService.java

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

    // This is specific to Heart Rate Measurement.
    if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
        BluetoothGattDescriptor descriptor = characteristic
                .getDescriptor(UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
    }
}

From source file:com.chenls.smartlock.UartService.java

/**
 * ???/* w w  w. j  a v  a 2s.com*/
 *
 * @param action
 * @param characteristic
 */
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.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));

    } else if (RX_CHAR_UUID.equals(characteristic.getUuid())) {
        intent.putExtra(CHAR1_DATA,
                "" + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));

    } else if (Battery_Level_UUID.equals(characteristic.getUuid())) {
        intent.putExtra(EXTRA_DATA,
                "" + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));
    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}

From source file:undot.safedrivers.BLE.BluetoothLeService.java

private void getGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null)
        return;//w ww . j  a  v a2  s . com
    String uuid = null;
    mModelNumberCharacteristic = null;
    mSerialPortCharacteristic = null;
    mCommandCharacteristic = null;
    mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>();

    // Loops through available GATT Services.
    for (BluetoothGattService gattService : gattServices) {
        uuid = gattService.getUuid().toString();
        System.out.println("displayGattServices + uuid=" + uuid);

        List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
        ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>();

        // Loops through available Characteristics.
        for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
            charas.add(gattCharacteristic);
            uuid = gattCharacteristic.getUuid().toString();
            if (uuid.equals(ModelNumberStringUUID)) {
                mModelNumberCharacteristic = gattCharacteristic;
                System.out.println(
                        "mModelNumberCharacteristic  " + mModelNumberCharacteristic.getUuid().toString());
            } else if (uuid.equals(SerialPortUUID)) {
                mSerialPortCharacteristic = gattCharacteristic;
                System.out.println(
                        "mSerialPortCharacteristic  " + mSerialPortCharacteristic.getUuid().toString());
                //                    updateConnectionState(R.string.comm_establish);
            } else if (uuid.equals(CommandUUID)) {
                mCommandCharacteristic = gattCharacteristic;
                System.out.println(
                        "mSerialPortCharacteristic  " + mSerialPortCharacteristic.getUuid().toString());
                //                    updateConnectionState(R.string.comm_establish);
            }
        }
        mGattCharacteristics.add(charas);
    }

    if (mModelNumberCharacteristic == null || mSerialPortCharacteristic == null
            || mCommandCharacteristic == null) {
        Log.d("charactaristics", "null");
        Toast.makeText(getApplicationContext(), "characteristics null", Toast.LENGTH_SHORT);
    } else {
        mSCharacteristic = mModelNumberCharacteristic;
        setCharacteristicNotification(mSCharacteristic, true);
        readCharacteristic(mSCharacteristic);
    }

}

From source file:com.cqupt.pedometer.main.UartService.java

/**
 * ???/*from ww  w  .  j a v  a  2 s.  c o m*/
 *
 * @param action
 * @param characteristic
 */
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())) {

        final byte[] data = characteristic.getValue();
        if (data != null && data.length > 0) {
            final StringBuilder stringBuilder = new StringBuilder(data.length);
            for (byte byteChar : data)
                stringBuilder.append(String.format("%X ", byteChar));
            String a = stringBuilder.toString();
            a = a.replaceAll("[^0-9a-zA-Z]", "");
            // String.subSequence(beginIndex, endIndex?)
            String b = (String) a.subSequence(0, 1);
            // ?
            String c = a.substring(1, a.length());
            // Integer.parseInt(s, radix) radix10101616
            int i = Integer.parseInt(c, 16);
            intent.putExtra(EXTRA_DATA, i + "");
            intent.putExtra(SAFE_DATA, b);
        }

    } else if (RX_CHAR_UUID.equals(characteristic.getUuid())) {
        intent.putExtra(CHAR1_DATA,
                "" + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));

    } else if (Battery_Level_UUID.equals(characteristic.getUuid())) {
        intent.putExtra(EXTRA_DATA,
                "" + characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));
    }
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}