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:org.zpcat.ble.ui.central.DeviceControlActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void displayGattServices(List<BluetoothGattService> gattServices) {
    Log.d("displayGATTServices");

    if (gattServices == null)
        return;//w  w w  .  j  a va 2 s  .  com
    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>();
        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>();

        // 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);
        }
        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.mikroe.hexiwear_android.DeviceScanActivity.java

private void displayGattServices(List<List<BluetoothGattService>> devicesGattServices) {
    if (devicesGattServices == null)
        return;//ww w. ja  v  a 2  s.  c om

    String uuid = null;
    ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>();
    ArrayList<ArrayList<HashMap<String, String>>> gattCharacteristicData = new ArrayList<ArrayList<HashMap<String, String>>>();
    ArrayList<ArrayList<BluetoothGattCharacteristic>> tempGattCharacteristics = new ArrayList<>();
    mGattsCharacteristics.clear();

    for (List<BluetoothGattService> gattServices : devicesGattServices) {
        // Loops through available GATT Services.
        for (BluetoothGattService gattService : gattServices) {
            HashMap<String, String> currentServiceData = new HashMap<String, String>();
            uuid = gattService.getUuid().toString();
            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>();

            // Loops through available Characteristics.
            for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {

                charas.add(gattCharacteristic);
                HashMap<String, String> currentCharaData = new HashMap<String, String>();
                uuid = gattCharacteristic.getUuid().toString();
                if (uuid.equals(UUID_CHAR_ALERTIN)) {
                    alertInCharacteristic = gattCharacteristic;
                    byte[] value = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                    alertInCharacteristic.setValue(value);
                }
                currentCharaData.put(LIST_UUID, uuid);
                gattCharacteristicGroupData.add(currentCharaData);
            }
            tempGattCharacteristics.add(charas);
            gattCharacteristicData.add(gattCharacteristicGroupData);
        }
        mGattsCharacteristics.add(tempGattCharacteristics);
    }
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            Intent intent = new Intent(DeviceScanActivity.this, MainScreenActivity.class);
            startActivity(intent);
        }
    }, 1500);
}

From source file:kr.ac.kaist.resl.sensorservice.BluetoothService.java

private boolean readCharacteristics(BluetoothGatt gatt) {
    if (null == gatt)
        return false;

    String deviceName = gatt.getDevice().getName();
    List<BluetoothGattService> gattServices = gatt.getServices();

    if (gattServices == null)
        return false;

    String unknownServiceString = getResources().getString(R.string.unknown_service);
    String unknownCharaString = getResources().getString(R.string.unknown_characteristic);

    // Find the device node from device-service-characteristic tree
    Node<String> deviceNode = null;
    for (Node<String> node : device_service_characteristicTree.getChildren()) {
        if (node.data.equals(deviceName)) {
            deviceNode = node;/*  ww  w.j  av  a2  s .  com*/
            break;
        }
    }

    // Loops through available GATT Services.
    for (BluetoothGattService gattService : gattServices) {
        String serviceUuid = gattService.getUuid().toString();
        String serviceName = SampleGattAttributes.lookup(serviceUuid, unknownServiceString);

        // Find desired service
        for (Node<String> serviceNode : deviceNode.getChildren()) {
            if (serviceName.equals(serviceNode.data)) {
                List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();

                // Loops through available Characteristics.
                for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
                    String characteristicUuid = gattCharacteristic.getUuid().toString();
                    String characteristicName = SampleGattAttributes.lookup(characteristicUuid,
                            unknownCharaString);

                    // Find desired characteristic of selected service
                    for (Node<String> characteristicNode : serviceNode.getChildren()) {
                        if (characteristicName.equals(characteristicNode.data)) {
                            Log.i(null, "FOUND DESIRED characteristic!!!");
                            readCharacteristic(gatt, gattCharacteristic);
                            break;
                        }
                    }

                }
            }
        }
    }
    return true;

}

From source file:io.v.android.impl.google.discovery.plugins.ble.Driver.java

private synchronized void startAdvertising(BluetoothGattService service) {
    mGattServer.addService(service);/*from  www . ja  va 2s . c  o m*/
    synchronized (Driver.class) {
        mClassicAdvertiser.addService(service.getUuid(), sClassicDiscoverableDurationInSec);
        sClassicDiscoverableDurationInSec = 0;
    }
    if (mLeAdvertiser != null) {
        final UUID uuid = service.getUuid();
        AdvertiseSettings settings = new AdvertiseSettings.Builder()
                .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED).setConnectable(true).build();
        AdvertiseData data = new AdvertiseData.Builder().addServiceUuid(new ParcelUuid(uuid))
                .setIncludeTxPowerLevel(true).build();
        AdvertiseCallback callback = new AdvertiseCallback() {
            @Override
            public void onStartFailure(int errorCode) {
                Log.e(TAG, "startAdvertising failed: " + uuid + ", errorCode:" + errorCode);
            }
        };
        // TODO(jhahn): The maximum number of simultaneous advertisements is limited by the chipset.
        // Rotate active advertisements periodically if the total number of advertisement exceeds
        // the limit.
        mLeAdvertiser.startAdvertising(settings, data, callback);
        mLeAdvertiseCallbacks.put(uuid, callback);
    }
}

From source file:com.polkapolka.bluetooth.le.DeviceControlActivity.java

private void displayGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null)
        return;//w w w  .  j a va  2 s .  co  m
    String uuid = null;
    String unknownServiceString = getResources().getString(R.string.unknown_service);
    ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>();

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

        // If the service exists for HM 10 Serial, say so.
        if (SampleGattAttributes.lookup(uuid, unknownServiceString) == "HM 10 Serial") {
            isSerial.setText(getString(R.string.verbinding_herkend));
        } else {
            isSerial.setText("No, serial :-(");
        }
        currentServiceData.put(LIST_UUID, uuid);
        gattServiceData.add(currentServiceData);

        // get characteristic when UUID matches RX/TX UUID
        characteristicTX = gattService.getCharacteristic(BluetoothLeService.UUID_HM_RX_TX);
        characteristicRX = gattService.getCharacteristic(BluetoothLeService.UUID_HM_RX_TX);
    }

}

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

private void displayGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null)
        return;//from  w  ww .j  a v  a2  s.  c  om
    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.google.android.apps.forscience.ble.MyBleService.java

public void printServices(String address) {
    BluetoothGatt bluetoothGatt = addressToGattClient.get(address);
    if (bluetoothGatt == null) {
        Log.d(TAG, "No connection found for: " + address);
        return;//w  ww .j  a v a2 s . c  om
    }
    for (BluetoothGattService service : bluetoothGatt.getServices()) {
        Log.d(TAG, "Service ================================");
        Log.d(TAG, "Service UUID: " + service.getUuid());
        Log.d(TAG, "Service Type: " + service.getType());

        for (BluetoothGattCharacteristic charact : service.getCharacteristics()) {
            Log.d(TAG, "Charact UUID: " + charact.getUuid());
            Log.d(TAG, "Charact prop: " + charact.getProperties());

            if (charact.getValue() != null) {
                Log.d(TAG, "Charact Value: " + new String(charact.getValue()));
            }
        }
    }
}

From source file:com.example.user.wase.view.fragment.EquipmentScanner.java

private void displayGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null)
        return;//w ww . j  av a 2 s.c  om
    String uuid = null;
    ArrayList<HashMap<String, String>> gattServiceData = new ArrayList<HashMap<String, String>>();

    // Loops through available GATT Services.
    for (BluetoothGattService gattService : gattServices) {
        HashMap<String, String> currentServiceData = new HashMap<String, String>();
        uuid = gattService.getUuid().toString();
        currentServiceData.put(LIST_NAME, HERE_GattAttributes.lookup(uuid, "unknown"));

        // If the service exists for HM 10 Serial, say so.
        if (HERE_GattAttributes.lookup(uuid, "unknown") == "HM 10 Serial") {
        } else {
        }
        currentServiceData.put(LIST_UUID, uuid);
        gattServiceData.add(currentServiceData);

        // get characteristic when UUID matches RX/TX UUID
        characteristicTX = gattService.getCharacteristic(BluetoothLeService.UUID_HM_RX_TX);
        characteristicRX = gattService.getCharacteristic(BluetoothLeService.UUID_HM_RX_TX);

        if (characteristicTX != null && mBluetoothLeService != null) {
            characteristicRX.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            mBluetoothLeService.writeCharacteristic(characteristicTX);
            mBluetoothLeService.setCharacteristicNotification(characteristicRX, true);
        }
    }

}

From source file:com.wearme.fat.ui.MainActivity.java

private void displayGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null)
        return;//www.j  a  v  a 2  s  .c o m
    for (BluetoothGattService gattService : gattServices) {
        //f433bd80
        //06aba6de
        if (gattService.getUuid().toString().startsWith("f433bd80")) {
            List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
            for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
                if (gattCharacteristic.getUuid().toString().startsWith("29f11080")) {

                    GattAttributes.mobileToEquipmentCharacteristic = gattCharacteristic;

                } else if (gattCharacteristic.getUuid().toString().startsWith("1a2ea400")) {
                    mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true);
                }
            }
        }

        if (gattService.getUuid().toString().startsWith("06aba6de")) {
            List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();
            for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
                if (gattCharacteristic.getUuid().toString().startsWith("29f11080")) {

                    GattAttributes.mobileToEquipmentCharacteristic = gattCharacteristic;

                } else if (gattCharacteristic.getUuid().toString().startsWith("1a2ea400")) {
                    mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true);
                }
            }
        }
    }
}

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

public JSONObject asJSONObject(BluetoothGatt gatt) {

    JSONObject json = asJSONObject();// w  w w  .  j  a  v a 2 s .c o  m

    try {
        JSONArray servicesArray = new JSONArray();
        JSONArray characteristicsArray = new JSONArray();
        json.put("services", servicesArray);
        json.put("characteristics", characteristicsArray);

        if (connected && gatt != null) {
            for (BluetoothGattService service : gatt.getServices()) {
                servicesArray.put(UUIDHelper.uuidToString(service.getUuid()));

                for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
                    JSONObject characteristicsJSON = new JSONObject();
                    characteristicsArray.put(characteristicsJSON);

                    characteristicsJSON.put("service", UUIDHelper.uuidToString(service.getUuid()));
                    characteristicsJSON.put("characteristic",
                            UUIDHelper.uuidToString(characteristic.getUuid()));
                    //characteristicsJSON.put("instanceId", characteristic.getInstanceId());

                    characteristicsJSON.put("properties", Helper.decodeProperties(characteristic));
                    // characteristicsJSON.put("propertiesValue", characteristic.getProperties());

                    if (characteristic.getPermissions() > 0) {
                        characteristicsJSON.put("permissions", Helper.decodePermissions(characteristic));
                        // characteristicsJSON.put("permissionsValue", characteristic.getPermissions());
                    }

                    JSONArray descriptorsArray = new JSONArray();

                    for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) {
                        JSONObject descriptorJSON = new JSONObject();
                        descriptorJSON.put("uuid", UUIDHelper.uuidToString(descriptor.getUuid()));
                        descriptorJSON.put("value", descriptor.getValue()); // always blank

                        if (descriptor.getPermissions() > 0) {
                            descriptorJSON.put("permissions", Helper.decodePermissions(descriptor));
                            // descriptorJSON.put("permissionsValue", descriptor.getPermissions());
                        }
                        descriptorsArray.put(descriptorJSON);
                    }
                    if (descriptorsArray.length() > 0) {
                        characteristicsJSON.put("descriptors", descriptorsArray);
                    }
                }
            }
        }
    } catch (JSONException e) { // TODO better error handling
        e.printStackTrace();
    }

    return json;
}