List of usage examples for android.bluetooth BluetoothGattCharacteristic getProperties
public int getProperties()
From source file:com.megster.cordova.ble.central.Peripheral.java
private BluetoothGattCharacteristic findWritableCharacteristic(BluetoothGattService service, UUID characteristicUUID, int writeType) { BluetoothGattCharacteristic characteristic = null; // get write property int writeProperty = BluetoothGattCharacteristic.PROPERTY_WRITE; if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE) { writeProperty = BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE; }/*from ww w . java2s . c om*/ List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); for (BluetoothGattCharacteristic c : characteristics) { if ((c.getProperties() & writeProperty) != 0 && characteristicUUID.equals(c.getUuid())) { characteristic = c; break; } } // As a last resort, try and find ANY characteristic with this UUID, even if it doesn't have the correct properties if (characteristic == null) { characteristic = service.getCharacteristic(characteristicUUID); } return characteristic; }
From source file:com.megster.cordova.ble.central.Peripheral.java
private BluetoothGattCharacteristic findNotifyCharacteristic(BluetoothGattService service, UUID characteristicUUID) { BluetoothGattCharacteristic characteristic = null; // Check for Notify first List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); for (BluetoothGattCharacteristic c : characteristics) { if ((c.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0 && characteristicUUID.equals(c.getUuid())) { characteristic = c;/* w ww. j a v a 2s .c om*/ break; } } if (characteristic != null) return characteristic; // If there wasn't Notify Characteristic, check for Indicate for (BluetoothGattCharacteristic c : characteristics) { if ((c.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0 && characteristicUUID.equals(c.getUuid())) { characteristic = c; break; } } // As a last resort, try and find ANY characteristic with this UUID, even if it doesn't have the correct properties if (characteristic == null) { characteristic = service.getCharacteristic(characteristicUUID); } return characteristic; }
From source file:com.touchKin.touchkinapp.DeviceControlActivity.java
private void readHeartRate() { // TODO Auto-generated method stub if (mConnected) { if (mBluetoothLeService.getSupportedGattService() != null) { Log.d("Read", "+++++++++++++Reading" + mBluetoothLeService.getSupportedGattService() .getCharacteristic(UUID.fromString("00001524-1212-efde-1523-785feabcd123"))); Toast.makeText(this, "" + mBluetoothLeService.getSupportedGattService() .getCharacteristic(UUID.fromString("00001524-1212-efde-1523-785feabcd123")), Toast.LENGTH_LONG).show(); BluetoothGattCharacteristic charprop = mBluetoothLeService.getSupportedGattService() .getCharacteristic(UUID.fromString("00001524-1212-efde-1523-785feabcd123")); if (charprop != null) { final int charaProp = charprop.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { mNotifyCharacteristic = charprop; mBluetoothLeService.setCharacteristicNotification(charprop, true); }//from w w w .ja v a 2s . c o m } else { Toast.makeText(this, "Unable to connect " + charprop, Toast.LENGTH_LONG).show(); } } else { Toast.makeText(this, "Unable to connect", Toast.LENGTH_LONG).show(); } } }
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;//from w ww.jav a 2 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:edu.stanford.cs.sing.helena.DeviceControlActivity.java
private void checkServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return;//from w ww . ja v a2 s .c om String uuid; // Loops through available GATT Services. for (BluetoothGattService gattService : gattServices) { uuid = gattService.getUuid().toString(); //only interested in helena service if (uuid.equals(HelenaGattAttributes.HELENA_SERVICE)) { mHelenaService = gattService; List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics(); // Loops through available Characteristics. for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { //only interested in this characteristic if (gattCharacteristic.getUuid().toString().equals(HelenaGattAttributes.UUID_LISTED_DEVICE)) { mNotifyCharacteristic = gattCharacteristic; final int charaProp = gattCharacteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { //Initiate notifications mNotifyCharacteristic = gattCharacteristic; mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, true); } } } } else { Log.d(TAG, "Skipping other services"); } } }
From source file:com.cypress.cysmart.RDKEmulatorView.RemoteControlEmulatorFragment.java
/** * stop notifications of all Report characteristc *///from www. j a v a 2 s . c o m private void stopBroadcastAllNotifications() { List<BluetoothGattCharacteristic> gattCharacteristics = mservice.getCharacteristics(); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { String uuidchara = gattCharacteristic.getUuid().toString(); if (uuidchara.equalsIgnoreCase(GattAttributes.REP0RT)) { final int charaProp = gattCharacteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { BluetoothLeService.setCharacteristicNotification(gattCharacteristic, false); } } } }
From source file:com.cypress.cysmart.GATTDBFragments.GattDetailsFragment.java
/** * Preparing Broadcast receiver to broadcast read characteristics * * @param gattCharacteristic// w ww . j ava 2 s . c o m */ void prepareBroadcastDataRead(BluetoothGattCharacteristic gattCharacteristic) { final BluetoothGattCharacteristic characteristic = gattCharacteristic; final int charaProp = characteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) { mReadCharacteristic = characteristic; BluetoothLeService.readCharacteristic(characteristic); } }
From source file:com.cypress.cysmart.GATTDBFragments.GattDetailsFragment.java
/** * Preparing Broadcast receiver to broadcast notify characteristics * * @param gattCharacteristic//from ww w .j av a 2s.c o m */ void prepareBroadcastDataNotify(BluetoothGattCharacteristic gattCharacteristic) { final BluetoothGattCharacteristic characteristic = gattCharacteristic; final int charaProp = characteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { mNotifyCharacteristic = characteristic; BluetoothLeService.setCharacteristicNotification(characteristic, true); } }
From source file:com.cypress.cysmart.GATTDBFragments.GattDetailsFragment.java
/** * Preparing Broadcast receiver to broadcast indicate characteristics * * @param gattCharacteristic/* w w w . j ava2 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//from w w w .j a va 2 s . com */ 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); } } }