Example usage for android.bluetooth BluetoothGattService getCharacteristics

List of usage examples for android.bluetooth BluetoothGattService getCharacteristics

Introduction

In this page you can find the example usage for android.bluetooth BluetoothGattService getCharacteristics.

Prototype

public List<BluetoothGattCharacteristic> getCharacteristics() 

Source Link

Document

Returns a list of characteristics included in this service.

Usage

From source file:com.muggins.test.ble.DeviceControlActivity.java

private void displayGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null)
        return;/*from w  w w. j a  v a 2  s .c  o m*/
    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.
    for (BluetoothGattService gattService : gattServices) {
        HashMap<String, String> currentServiceData = new HashMap<String, String>();
        if (SampleGattAttributes.SERVICE_NUMBER.equals(gattService.getUuid().toString())) {
            uuid = gattService.getUuid().toString();

            //                currentServiceData.put(LIST_NAME, "?");
            //                currentServiceData.put(LIST_UUID, "??1234");
            //                gattServiceData.add(currentServiceData);

            ArrayList<HashMap<String, String>> gattCharacteristicGroupData = new ArrayList<HashMap<String, String>>();
            List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
            ArrayList<BluetoothGattCharacteristic> charas = new ArrayList<BluetoothGattCharacteristic>();

            // Loops through available Characteristics.
            for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
                charas.add(gattCharacteristic);
                HashMap<String, String> currentCharaData = new HashMap<String, String>();
                if (SampleGattAttributes.HEART_RATE_MEASUREMENT
                        .equals(gattCharacteristic.getUuid().toString())) {
                    uuid = gattCharacteristic.getUuid().toString();

                    currentCharaData.put(LIST_NAME, "?");
                    currentCharaData.put(LIST_UUID, "");
                    gattCharacteristicGroupData.add(currentCharaData);

                    final int charaProp = gattCharacteristic.getProperties();
                    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
                        // If there is an active notification on a characteristic, clear
                        // it first so it doesn't update the data field on the user interface.
                        Log.e("BluetoothLeService", "read");
                        if (mNotifyCharacteristic != null) {
                            mBluetoothLeService.setCharacteristicNotification(
                                    //                                        mNotifyCharacteristic, false);
                                    mNotifyCharacteristic, true);
                            mNotifyCharacteristic = null;
                        }
                        mBluetoothLeService.readCharacteristic(gattCharacteristic);
                        //                            Intent intent = new Intent(DeviceControlActivity.this, ShowWave.class);
                        //                            startActivity(intent);
                    }
                    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
                        Log.e("BluetoothLeService", "notify");
                        mNotifyCharacteristic = gattCharacteristic;
                        mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true);
                    }

                }
            }
            mGattCharacteristics.add(charas);
            gattCharacteristicData.add(gattCharacteristicGroupData);
        }
    }

    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.ucai.test.control.DeviceControlActivity.java

/**
 * ???GATT?/?/*from w  w w  .j a  va  2s.  com*/
 * ,?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.cypress.cysmart.ListAdapters.CarouselPagerAdapter.java

@Override
public Fragment getItem(int position) {

    // Make the first pager bigger than others
    if (position == ProfileControlFragment.FIRST_PAGE) {
        scale = ProfileControlFragment.BIG_SCALE;
    } else {//  w  ww  .j  ava2s .  com
        scale = ProfileControlFragment.SMALL_SCALE;
    }
    position = position % ProfileControlFragment.PAGES;
    HashMap<String, BluetoothGattService> item = currentServiceData.get(position);
    BluetoothGattService bgs = item.get("UUID");

    /**
     * Looking for the image corresponding to the UUID.if no suitable image
     * resource is found assign the default unknown resource
     */

    int imageId = GattAttributes.lookupImage(bgs.getUuid().toString());
    String name = GattAttributes.lookup(bgs.getUuid().toString(),
            context.getResources().getString(R.string.profile_control_unknown_service));
    String uuid = bgs.getUuid().toString();
    if (uuid.equalsIgnoreCase(GattAttributes.IMMEDIATE_ALERT_SERVICE)) {
        name = context.getResources().getString(R.string.findme_fragment);
    }
    if (uuid.equalsIgnoreCase(GattAttributes.LINK_LOSS_SERVICE)
            || uuid.equalsIgnoreCase(GattAttributes.TRANSMISSION_POWER_SERVICE)) {
        name = context.getResources().getString(R.string.proximity_fragment);
    }
    if (uuid.equalsIgnoreCase(GattAttributes.CAPSENSE_SERVICE)
            || uuid.equalsIgnoreCase(GattAttributes.CAPSENSE_SERVICE_CUSTOM)) {
        List<BluetoothGattCharacteristic> gattCharacteristics = bgs.getCharacteristics();
        if (gattCharacteristics.size() > 1) {
            imageId = GattAttributes.lookupImageCapSense(bgs.getUuid().toString());
            name = GattAttributes.lookupNameCapSense(bgs.getUuid().toString(),
                    context.getResources().getString(R.string.profile_control_unknown_service));
        } else {
            String characteristicUUID = gattCharacteristics.get(0).getUuid().toString();
            imageId = GattAttributes.lookupImageCapSense(characteristicUUID);
            name = GattAttributes.lookupNameCapSense(characteristicUUID,
                    context.getResources().getString(R.string.profile_control_unknown_service));
        }
    }
    if (uuid.equalsIgnoreCase(GattAttributes.GENERIC_ACCESS_SERVICE)
            || uuid.equalsIgnoreCase(GattAttributes.GENERIC_ATTRIBUTE_SERVICE)) {
        name = context.getResources().getString(R.string.gatt_db);
    }
    if (uuid.equalsIgnoreCase(GattAttributes.BAROMETER_SERVICE)
            || uuid.equalsIgnoreCase(GattAttributes.ACCELEROMETER_SERVICE)
            || uuid.equalsIgnoreCase(GattAttributes.ANALOG_TEMPERATURE_SERVICE)) {
        name = context.getResources().getString(R.string.sen_hub);
    }
    if (uuid.equalsIgnoreCase(GattAttributes.HUMAN_INTERFACE_DEVICE_SERVICE)) {
        String connectedDeviceName = BluetoothLeService.getmBluetoothDeviceName();
        String remoteName = context.getString(R.string.rdk_emulator_view);
        if (connectedDeviceName.indexOf(remoteName) != -1) {
            name = context.getResources().getString(R.string.rdk_emulator_view);
            imageId = R.drawable.emulator;
        }

    }
    Fragment curFragment = CarouselFragment.newInstance(imageId, scale, name, uuid, bgs);
    return curFragment;
}

From source file:com.cypress.cysmart.BLEServiceFragments.SensorHubService.java

/**
 * Method to get required characteristics from service
 *///from  w  w  w  .  j  a v  a  2 s . co  m
void getGattData() {
    for (int position = 0; position < mExtraservice.size(); position++) {
        HashMap<String, BluetoothGattService> item = mExtraservice.get(position);
        BluetoothGattService bgs = item.get("UUID");
        if (bgs.getUuid().equals(UUIDDatabase.UUID_ACCELEROMETER_SERVICE)) {
            mAccservice = bgs;
        }
        List<BluetoothGattCharacteristic> gattCharacteristicsCurrent = bgs.getCharacteristics();
        for (final BluetoothGattCharacteristic gattCharacteristic : gattCharacteristicsCurrent) {
            String uuidchara = gattCharacteristic.getUuid().toString();
            if (uuidchara.equalsIgnoreCase(GattAttributes.ACCELEROMETER_READING_X)) {
                mReadACCXCharacteristic = gattCharacteristic;
                mNotifyACCXCharacteristic = gattCharacteristic;

                prepareBroadcastDataRead(mReadACCXCharacteristic);
            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.ACCELEROMETER_READING_Y)) {
                mReadACCYCharacteristic = gattCharacteristic;
                mNotifyACCYCharacteristic = gattCharacteristic;

            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.ACCELEROMETER_READING_Z)) {
                mReadACCZCharacteristic = gattCharacteristic;
                mNotifyACCZCharacteristic = gattCharacteristic;
            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.BATTERY_LEVEL)) {
                mReadBATCharacteristic = gattCharacteristic;
                mNotifyBATCharacteristic = gattCharacteristic;
            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.TEMPERATURE_READING)) {
                mReadSTEMPCharacteristic = gattCharacteristic;
                mNotifySTEMPCharacteristic = gattCharacteristic;
            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.BAROMETER_READING)) {
                mReadSPRESSURECharacteristic = gattCharacteristic;
                mIndicateSPRESSURECharacteristic = gattCharacteristic;
            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.ALERT_LEVEL)) {
                mWriteAlertCharacteristic = gattCharacteristic;

            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.ACCELEROMETER_SENSOR_SCAN_INTERVAL)) {
                mReadACCSensorScanCharacteristic = gattCharacteristic;

            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.ACCELEROMETER_ANALOG_SENSOR)) {
                mReadACCSensorTypeCharacteristic = gattCharacteristic;
            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.ACCELEROMETER_DATA_ACCUMULATION)) {
                mReadACCFilterConfigurationCharacteristic = gattCharacteristic;
            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.TEMPERATURE_SENSOR_SCAN_INTERVAL)) {
                mReadSTEMPSensorScanCharacteristic = gattCharacteristic;

            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.TEMPERATURE_ANALOG_SENSOR)) {
                mReadSTEMPSensorTypeCharacteristic = gattCharacteristic;
            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.BAROMETER_SENSOR_SCAN_INTERVAL)) {
                mReadSPRESSURESensorScanCharacteristic = gattCharacteristic;

            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.BAROMETER_DIGITAL_SENSOR)) {
                mReadSPRESSURESensorTypeCharacteristic = gattCharacteristic;
            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.BAROMETER_DATA_ACCUMULATION)) {
                mReadSPRESSUREFilterConfigurationCharacteristic = gattCharacteristic;
            }
            if (uuidchara.equalsIgnoreCase(GattAttributes.BAROMETER_THRESHOLD_FOR_INDICATION)) {
                mReadSPRESSUREThresholdCharacteristic = gattCharacteristic;
            }
        }
    }
}