Example usage for android.bluetooth BluetoothGattDescriptor getValue

List of usage examples for android.bluetooth BluetoothGattDescriptor getValue

Introduction

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

Prototype

public byte[] getValue() 

Source Link

Document

Returns the stored value for this descriptor

This function returns the stored value for this descriptor as retrieved by calling BluetoothGatt#readDescriptor .

Usage

From source file:Main.java

public static String formatGattDescriptor(BluetoothGattDescriptor descriptor) {
    String log = "";
    if (descriptor == null) {
        log += "<null>";
    } else {/*from www.  java  2  s .  c  o  m*/
        log += "descriptorUUID=" + descriptor.getUuid();
        log += "descriptorValue=" + descriptor.getValue();
    }
    return log;
}

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

public JSONObject asJSONObject(BluetoothGatt gatt) {

    JSONObject json = asJSONObject();/*from  w  w  w  . j  a  v a2s.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;
}

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

private void readValueManage(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
    String deviceAddress = getDeviceAddress(gatt);
    JSONObject obj = new JSONObject();
    if (readValueCC.get(deviceAddress) != null) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            Tools.addProperty(obj, Tools.DEVICE_ADDRESS, deviceAddress);
            Tools.addProperty(obj, Tools.VALUE, Tools.encodeBase64(descriptor.getValue()));
            Tools.addProperty(obj, Tools.DATE, Tools.getDateString());
            readValueCC.get(deviceAddress).success(obj);
            readValueCC.remove(deviceAddress);
        } else {/*w ww . ja  v  a 2 s .c  o  m*/
            Tools.sendErrorMsg(readValueCC.get(deviceAddress));
            readValueCC.remove(deviceAddress);
        }
    }
}