Example usage for android.bluetooth BluetoothGattService getUuid

List of usage examples for android.bluetooth BluetoothGattService getUuid

Introduction

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

Prototype

public UUID getUuid() 

Source Link

Document

Returns the UUID of this service

Usage

From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java

/**
 * Prepare GATTServices data.// w w  w.j a  v a  2 s .  c om
 *
 * @param gattServices
 */
private void prepareData(List<BluetoothGattService> gattServices) {
    boolean mFindmeSet = false;
    boolean mProximitySet = false;
    boolean mGattSet = false;
    if (gattServices == null)
        return;
    // Clear all array list before entering values.
    gattServiceData.clear();
    gattServiceFindMeData.clear();
    gattServiceMasterData.clear();

    // Loops through available GATT Services.
    for (BluetoothGattService gattService : gattServices) {
        HashMap<String, BluetoothGattService> currentServiceData = new HashMap<String, BluetoothGattService>();
        String uuid = gattService.getUuid().toString();
        // Optimization code for FindMe Profile
        if (uuid.equalsIgnoreCase(GattAttributes.IMMEDIATE_ALERT_SERVICE)) {
            currentServiceData.put(LIST_UUID, gattService);
            gattServiceMasterData.add(currentServiceData);
            if (!gattServiceFindMeData.contains(currentServiceData)) {
                gattServiceFindMeData.add(currentServiceData);
            }
            if (!mFindmeSet) {
                mFindmeSet = true;
                gattServiceData.add(currentServiceData);
            }

        }
        // Optimization code for Proximity Profile
        else if (uuid.equalsIgnoreCase(GattAttributes.LINK_LOSS_SERVICE)
                || uuid.equalsIgnoreCase(GattAttributes.TRANSMISSION_POWER_SERVICE)) {
            currentServiceData.put(LIST_UUID, gattService);
            gattServiceMasterData.add(currentServiceData);
            if (!gattServiceProximityData.contains(currentServiceData)) {
                gattServiceProximityData.add(currentServiceData);
            }
            if (!mProximitySet) {
                mProximitySet = true;
                gattServiceData.add(currentServiceData);
            }

        } // Optimization code for GATTDB
        else if (uuid.equalsIgnoreCase(GattAttributes.GENERIC_ACCESS_SERVICE)
                || uuid.equalsIgnoreCase(GattAttributes.GENERIC_ATTRIBUTE_SERVICE)) {
            currentServiceData.put(LIST_UUID, gattService);
            gattdbServiceData.add(currentServiceData);
            if (!mGattSet) {
                mGattSet = true;
                gattServiceData.add(currentServiceData);
            }

        } else {
            currentServiceData.put(LIST_UUID, gattService);
            gattServiceMasterData.add(currentServiceData);
            gattServiceData.add(currentServiceData);
        }

    }
    application.setGattServiceData(gattServiceData);
    application.setGattServiceMasterData(gattServiceMasterData);

    // All service discovered and optimized.Dismiss the alert dialog
    if (gattdbServiceData.size() > 0) {
        mConnectHandler.removeCallbacksAndMessages(null);
        if (mpdia != null && mpdia.isShowing()) {
            mpdia.dismiss();
        }
        /**
         * Setting the handler flag to false. adding new fragment
         * ProfileControlFragment to the view
         */
        HANDLER_FLAG = false;
        if (receiverEnabled) {
            Logger.e("unregisterReceiver---->");
            getActivity().unregisterReceiver(mGattUpdateReceiver);
            receiverEnabled = false;
            FragmentManager fragmentManager = getFragmentManager();
            ProfileControlFragment profileControlFragment = new ProfileControlFragment().create(mDeviceName,
                    mDeviceAddress);
            fragmentManager.beginTransaction()
                    .add(R.id.container, profileControlFragment, Constants.PROFILE_CONTROL_FRAGMENT_TAG)
                    .addToBackStack(null).commit();
        }

    }

}

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

/**
 * Method to get required characteristics from service
 *///from w  w  w  .j  a  va2  s.c o 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;
            }
        }
    }
}