Example usage for android.bluetooth BluetoothGattDescriptor BluetoothGattDescriptor

List of usage examples for android.bluetooth BluetoothGattDescriptor BluetoothGattDescriptor

Introduction

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

Prototype

public BluetoothGattDescriptor(UUID uuid, int permissions) 

Source Link

Document

Create a new BluetoothGattDescriptor.

Usage

From source file:org.bcsphere.bluetooth.BluetoothG43plus.java

@Override
public void addServices(JSONArray json, CallbackContext callbackContext) {
    Log.i(TAG, "addServices");
    if (!isOpenGattServer) {
        mBluetoothGattServer = mBluetoothManager.openGattServer(mContext, mGattServerCallback);
        isOpenGattServer = true;/*  www.  j  a va  2 s . com*/
    }
    addServiceCC = callbackContext;
    JSONArray services = Tools.getArray(json, Tools.SERVICES);
    gattServerSum = services.length();
    for (int i = 0; i < services.length(); i++) {
        String uniqueID = Tools.getData(services, i, Tools.UINQUE_ID);
        int serviceType = -1;
        if (Tools.getData(services, i, Tools.SERVICE_TYPE).equals("0")) {
            serviceType = BluetoothGattService.SERVICE_TYPE_PRIMARY;
        } else {
            serviceType = BluetoothGattService.SERVICE_TYPE_SECONDARY;
        }
        UUID serviceUUID = UUID.fromString(Tools.getData(services, i, Tools.SERVICE_UUID));
        BluetoothGattService service = new BluetoothGattService(serviceUUID, serviceType);
        JSONArray characteristics = Tools.getArray(services, i, Tools.CHARACTERISTICS);
        for (int j = 0; j < characteristics.length(); j++) {
            byte[] characteristicValue = Tools
                    .decodeBase64(Tools.getData(characteristics, Tools.CHARACTERISTIC_VALUE));
            UUID characteristicUUID = UUID
                    .fromString(Tools.getData(characteristics, Tools.CHARACTERISTIC_UUID));
            int characteristicProperty = Tools
                    .encodeProperty(Tools.getArray(characteristics, Tools.CHARACTERISTIC_PROPERTY));
            int characteristicPermission = Tools
                    .encodePermission(Tools.getArray(characteristics, Tools.CHARACTERISTIC_PERMISSION));
            BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(characteristicUUID,
                    characteristicProperty, characteristicPermission);
            characteristic.setValue(characteristicValue);
            JSONArray descriptors = Tools.getArray(characteristics, j, Tools.DESCRIPTORS);
            for (int k = 0; k < descriptors.length(); k++) {
                byte[] descriptorValue = Tools.decodeBase64(Tools.getData(descriptors, Tools.DESCRIPTOR_VALUE));
                UUID descriptorUUID = UUID.fromString(Tools.getData(descriptors, Tools.DESCRIPTOR_UUID));
                int descriptorPermission = Tools
                        .encodePermission(Tools.getArray(descriptors, Tools.DESCRIPTOR_PERMISSION));
                BluetoothGattDescriptor descriptor = new BluetoothGattDescriptor(descriptorUUID,
                        descriptorPermission);
                descriptor.setValue(descriptorValue);
                characteristic.addDescriptor(descriptor);
            }
            service.addCharacteristic(characteristic);
        }
        if (mBluetoothGattServer.addService(service)) {
            localServices.put(uniqueID, service);
        }
    }
}

From source file:com.elitise.appv2.Peripheral.java

public static BluetoothGattDescriptor getClientCharacteristicConfigurationDescriptor() {
    return new BluetoothGattDescriptor(CLIENT_CHARACTERISTIC_CONFIGURATION_UUID,
            (BluetoothGattDescriptor.PERMISSION_WRITE | BluetoothGattDescriptor.PERMISSION_READ));
}

From source file:com.elitise.appv2.Peripheral.java

public static BluetoothGattDescriptor getClientCharacteristicExtendedDescriptor() {
    return new BluetoothGattDescriptor(CLIENT_CHARACTERISTIC_EXTENDED_UUID,
            (BluetoothGattDescriptor.PERMISSION_WRITE | BluetoothGattDescriptor.PERMISSION_READ));
}