Example usage for android.bluetooth BluetoothGattCharacteristic PROPERTY_INDICATE

List of usage examples for android.bluetooth BluetoothGattCharacteristic PROPERTY_INDICATE

Introduction

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

Prototype

int PROPERTY_INDICATE

To view the source code for android.bluetooth BluetoothGattCharacteristic PROPERTY_INDICATE.

Click Source Link

Document

Characteristic property: Characteristic supports indication

Usage

From source file:com.cypress.cysmart.GATTDBFragments.GattDescriptorDetails.java

/**
 * Stopping Broadcast receiver to broadcast indicate characteristics
 *
 * @param gattCharacteristic//from   w w w. j  ava2  s.c  om
 */
void stopBroadcastDataIndicate(BluetoothGattCharacteristic gattCharacteristic) {
    Logger.i("Indicate stopped");
    final BluetoothGattCharacteristic characteristic = gattCharacteristic;
    final int charaProp = characteristic.getProperties();

    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) {
        if (gattCharacteristic != null) {
            Logger.d("Stopped notification");
            BluetoothLeService.setCharacteristicIndication(gattCharacteristic, false);
        }

    }
}

From source file:com.cypress.cysmart.GATTDBFragments.GattDetailsFragment.java

/**
 * Method to make the Buttons visible to the user
 *//*from   w  w  w.  j  a  v a  2  s . c o  m*/
private void UIbuttonvisibility() {
    // Getting the properties of each characteristics
    boolean read = false, write = false, notify = false, indicate = false;
    if (getGattCharacteristicsPropertices(mReadCharacteristic.getProperties(),
            BluetoothGattCharacteristic.PROPERTY_READ)) {
        // Read property available
        read = true;
        mBtnread.setVisibility(View.VISIBLE);
    }
    if (getGattCharacteristicsPropertices(mReadCharacteristic.getProperties(),
            BluetoothGattCharacteristic.PROPERTY_WRITE)
            | getGattCharacteristicsPropertices(mReadCharacteristic.getProperties(),
                    BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) {
        // Write property available
        write = true;
        mBtnwrite.setVisibility(View.VISIBLE);
    }
    if (getGattCharacteristicsPropertices(mReadCharacteristic.getProperties(),
            BluetoothGattCharacteristic.PROPERTY_NOTIFY)) {
        // Notify property available
        notify = true;
        mBtnnotify.setVisibility(View.VISIBLE);
        BluetoothGattDescriptor descriptor = mReadCharacteristic
                .getDescriptor(UUIDDatabase.UUID_CLIENT_CHARACTERISTIC_CONFIG);
        if (descriptor != null) {
            BluetoothLeService.readDescriptor(descriptor);
        }
    }
    if (getGattCharacteristicsPropertices(mReadCharacteristic.getProperties(),
            BluetoothGattCharacteristic.PROPERTY_INDICATE)) {
        // Indicate property available
        indicate = true;
        mBtnIndicate.setVisibility(View.VISIBLE);
        BluetoothGattDescriptor descriptor = mReadCharacteristic
                .getDescriptor(UUIDDatabase.UUID_CLIENT_CHARACTERISTIC_CONFIG);
        if (descriptor != null) {
            BluetoothLeService.readDescriptor(descriptor);
        }
    }

}

From source file:com.cypress.cysmart.GATTDBFragments.GattDetailsFragment.java

/**
 * Preparing Broadcast receiver to broadcast indicate characteristics
 *
 * @param gattCharacteristic/*from   w w  w .j a  v  a2 s. c o m*/
 */
void prepareBroadcastDataIndicate(BluetoothGattCharacteristic gattCharacteristic) {
    final BluetoothGattCharacteristic characteristic = gattCharacteristic;
    final int charaProp = characteristic.getProperties();

    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) {
        mIndicateCharacteristic = characteristic;
        BluetoothLeService.setCharacteristicIndication(mIndicateCharacteristic, true);

    }

}

From source file:com.cypress.cysmart.GATTDBFragments.GattDetailsFragment.java

/**
 * Stopping Broadcast receiver to broadcast indicate characteristics
 *
 * @param gattCharacteristic//www .  j av  a 2 s .c o  m
 */
void stopBroadcastDataIndicate(BluetoothGattCharacteristic gattCharacteristic) {
    final BluetoothGattCharacteristic characteristic = gattCharacteristic;
    final int charaProp = characteristic.getProperties();

    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) {
        if (mIndicateCharacteristic != null) {
            BluetoothLeService.setCharacteristicIndication(mIndicateCharacteristic, false);
        }

    }

}

From source file:org.bcsphere.bluetooth.tools.Tools.java

public static JSONArray decodeProperty(int property) {
    JSONArray properties = new JSONArray();
    String strProperty = null;//from   w w w  .ja  v a 2 s .  c om
    if ((strProperty = lookup(property, BluetoothGattCharacteristic.PROPERTY_BROADCAST)) != null) {
        properties.put(strProperty);
    }
    if ((strProperty = lookup(property, BluetoothGattCharacteristic.PROPERTY_READ)) != null) {
        properties.put(strProperty);
    }
    if ((strProperty = lookup(property, BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) != null) {
        properties.put(strProperty);
    }
    if ((strProperty = lookup(property, BluetoothGattCharacteristic.PROPERTY_WRITE)) != null) {
        properties.put(strProperty);
    }
    if ((strProperty = lookup(property, BluetoothGattCharacteristic.PROPERTY_NOTIFY)) != null) {
        properties.put(strProperty);
    }
    if ((strProperty = lookup(property, BluetoothGattCharacteristic.PROPERTY_INDICATE)) != null) {
        properties.put(strProperty);
    }
    if ((strProperty = lookup(property, BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE)) != null) {
        properties.put(strProperty);
    }
    if ((strProperty = lookup(property, BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS)) != null) {
        properties.put(strProperty);
    }
    return properties;
}

From source file:com.nbplus.iotapp.bluetooth.BluetoothLeService.java

/**
 * Enables or disables notification on a give characteristic.
 *
 * @param enabled If true, enable notification.  False otherwise.
 *///  ww w .j av  a2  s  . c o  m
public boolean setCharacteristicNotification(String address, String serviceUuid, String characteristicUuid,
        boolean enabled) {
    Log.d(TAG, "writeRemoteCharacteristic add = " + address + ", svc = " + serviceUuid + ", char = "
            + characteristicUuid);
    if (StringUtils.isEmptyString(address) || StringUtils.isEmptyString(serviceUuid)
            || StringUtils.isEmptyString(characteristicUuid)) {
        Log.w(TAG, "Unknown parameter");
        return false;
    }
    BluetoothGatt bluetoothGatt = mConnectedBluetoothGattMap.get(address);
    if (mBluetoothAdapter == null || bluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return false;
    }
    BluetoothGattService service = bluetoothGatt.getService(UUID.fromString(serviceUuid));
    if (service == null) {
        Log.w(TAG, "Service not found.");
        return false;
    }
    BluetoothGattCharacteristic characteristic = service.getCharacteristic(UUID.fromString(characteristicUuid));
    if (characteristic == null) {
        Log.w(TAG, "characteristic not found.");
        return false;
    }

    bluetoothGatt.setCharacteristicNotification(characteristic, enabled);

    final int charaProp = characteristic.getProperties();
    if ((charaProp & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
        BluetoothGattDescriptor descriptor = characteristic
                .getDescriptor(UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
        if (descriptor != null) {
            Log.d(TAG, ">>>> ENABLE_NOTIFICATION_VALUE : " + characteristic.getUuid().toString());
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            bluetoothGatt.writeDescriptor(descriptor);

            return true;
        } else {
            return false;
        }
    } else if ((charaProp & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) {
        BluetoothGattDescriptor descriptor = characteristic
                .getDescriptor(UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
        if (descriptor != null) {
            Log.d(TAG, ">>>> ENABLE_INDICATION_VALUE : " + characteristic.getUuid().toString());
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
            bluetoothGatt.writeDescriptor(descriptor);

            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

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

/**
 * Stopping Broadcast receiver to broadcast indicate characteristics
 *
 * @param gattCharacteristic//w ww  . j  a v  a2  s .com
 */
private static void stopBroadcastDataIndicate(BluetoothGattCharacteristic gattCharacteristic) {
    final int charaProp = gattCharacteristic.getProperties();

    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) {
        if (gattCharacteristic != null) {
            BluetoothLeService.setCharacteristicNotification(gattCharacteristic, false);

        }

    }

}

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

/**
 * Preparing Broadcast receiver to broadcast indicate characteristics
 *
 * @param gattCharacteristic//  w  ww  .  j ava 2s . co  m
 */
void prepareBroadcastDataIndicate(BluetoothGattCharacteristic gattCharacteristic) {
    final int charaProp = gattCharacteristic.getProperties();

    if ((charaProp | BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) {
        BluetoothLeService.setCharacteristicNotification(gattCharacteristic, true);

    }

}