Java Code Examples for android.bluetooth.BluetoothGattCharacteristic#PROPERTY_INDICATE

The following examples show how to use android.bluetooth.BluetoothGattCharacteristic#PROPERTY_INDICATE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BleManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 8 votes vote down vote up
private boolean internalEnableIndications(final BluetoothGattCharacteristic characteristic) {
	final BluetoothGatt gatt = bluetoothGatt;
	if (gatt == null || characteristic == null)
		return false;

	// Check characteristic property
	final int properties = characteristic.getProperties();
	if ((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE) == 0)
		return false;

	gatt.setCharacteristicNotification(characteristic, true);
	final BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
	if (descriptor != null) {
		descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
		return internalWriteDescriptorWorkaround(descriptor);
	}
	return false;
}
 
Example 2
Source File: HealthThermometerServiceFragment.java    From ble-test-peripheral-android with Apache License 2.0 7 votes vote down vote up
public HealthThermometerServiceFragment() {
  mTemperatureMeasurementCharacteristic =
      new BluetoothGattCharacteristic(TEMPERATURE_MEASUREMENT_UUID,
          BluetoothGattCharacteristic.PROPERTY_INDICATE,
          /* No permissions */ 0);

  mTemperatureMeasurementCharacteristic.addDescriptor(
      Peripheral.getClientCharacteristicConfigurationDescriptor());

  mTemperatureMeasurementCharacteristic.addDescriptor(
      Peripheral.getCharacteristicUserDescriptionDescriptor(TEMPERATURE_MEASUREMENT_DESCRIPTION));

  mMeasurementIntervalCharacteristic =
      new BluetoothGattCharacteristic(
          MEASUREMENT_INTERVAL_UUID,
          (BluetoothGattCharacteristic.PROPERTY_READ |
              BluetoothGattCharacteristic.PROPERTY_WRITE |
              BluetoothGattCharacteristic.PROPERTY_INDICATE),
          (BluetoothGattCharacteristic.PERMISSION_READ |
              BluetoothGattCharacteristic.PERMISSION_WRITE));

  mMeasurementIntervalCCCDescriptor = Peripheral.getClientCharacteristicConfigurationDescriptor();
  mMeasurementIntervalCharacteristic.addDescriptor(mMeasurementIntervalCCCDescriptor);

  mMeasurementIntervalCharacteristic.addDescriptor(
      Peripheral.getCharacteristicUserDescriptionDescriptor(MEASUREMENT_INTERVAL_DESCRIPTION));

  mHealthThermometerService = new BluetoothGattService(HEALTH_THERMOMETER_SERVICE_UUID,
      BluetoothGattService.SERVICE_TYPE_PRIMARY);
  mHealthThermometerService.addCharacteristic(mTemperatureMeasurementCharacteristic);
  mHealthThermometerService.addCharacteristic(mMeasurementIntervalCharacteristic);
}
 
Example 3
Source File: BleGattImpl.java    From EasyBle with Apache License 2.0 6 votes vote down vote up
private Map<ServiceInfo, List<CharacteristicInfo>> getServiceInfoMap(List<BluetoothGattService> gattServices) {
    Map<ServiceInfo, List<CharacteristicInfo>> servicesInfoMap = new HashMap<>();
    for (BluetoothGattService service : gattServices) {
        String uuid = service.getUuid().toString();
        ServiceInfo serviceInfo = new ServiceInfo(uuid);
        List<CharacteristicInfo> charactInfos = new ArrayList<>();
        for (BluetoothGattCharacteristic ch : service.getCharacteristics()) {
            String chUuid = ch.getUuid().toString();
            boolean readable = (ch.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) > 0;
            boolean writable = (ch.getProperties() & (BluetoothGattCharacteristic.PROPERTY_WRITE |
                    BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE)) > 0;
            boolean notify = (ch.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0;
            boolean indicate = (ch.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0;
            CharacteristicInfo charactInfo = new CharacteristicInfo(chUuid, readable, writable, notify, indicate);
            charactInfos.add(charactInfo);
        }
        servicesInfoMap.put(serviceInfo, charactInfos);
    }
    return servicesInfoMap;
}
 
Example 4
Source File: BleRequestImpl.java    From Android-BLE with Apache License 2.0 6 votes vote down vote up
private void setCharacteristicNotificationInternal(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, boolean enabled){
    gatt.setCharacteristicNotification(characteristic, enabled);
    //If the number of descriptors in the eigenvalue of the notification is greater than zero
    if (characteristic.getDescriptors().size() > 0) {
        //Filter descriptors based on the uuid of the descriptor
        List<BluetoothGattDescriptor> descriptors = characteristic.getDescriptors();
        for(BluetoothGattDescriptor descriptor : descriptors){
            if (descriptor != null) {
                //Write the description value
                if((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0){
                    descriptor.setValue(enabled?BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE:BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
                }else if((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0){
                    //两个都是通知的意思,notify和indication的区别在于,notify只是将你要发的数据发送给手机,没有确认机制,
                    //不会保证数据发送是否到达。而indication的方式在手机收到数据时会主动回一个ack回来。即有确认机制,只有收
                    //到这个ack你才能继续发送下一个数据。这保证了数据的正确到达,也起到了流控的作用。所以在打开通知的时候,需要设置一下。
                    descriptor.setValue(enabled?BluetoothGattDescriptor.ENABLE_INDICATION_VALUE:BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
                }
                gatt.writeDescriptor(descriptor);
                BleLog.d(TAG, "setCharacteristicNotificationInternal is "+enabled);
            }
        }
    }
}
 
Example 5
Source File: CharacteristicDetailActivity.java    From AndroidBleManager with Apache License 2.0 6 votes vote down vote up
private String getPropertyString(int property){
    StringBuilder sb = new StringBuilder();
    // 可读
    if ((property & BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
        sb.append("Read ");
    }
    // 可写,注:要 & 其可写的两个属性
    if ((property & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) > 0
            || (property & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0) {
        sb.append("Write ");
    }
    // 可通知,可指示
    if ((property & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0
            || (property & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) {
        sb.append("Notity Indicate ");
    }
    // 广播
    if ((property & BluetoothGattCharacteristic.PROPERTY_BROADCAST) > 0){
        sb.append("Broadcast ");
    }
    sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
}
 
Example 6
Source File: P_Task_ToggleNotify.java    From AsteroidOSSync with GNU General Public License v3.0 6 votes vote down vote up
static byte[] getWriteValue(BluetoothGattCharacteristic char_native, boolean enable)
{
	final int type;
	
	if( (char_native.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0x0 )
	{
		type = Type_NOTIFY;
	}
	else if( (char_native.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0x0 )
	{
		type = Type_INDICATE;
	}
	else
	{
		type = Type_NOTIFY;
	}
	
	final byte[] enableValue = type == Type_NOTIFY ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.ENABLE_INDICATION_VALUE;
	final byte[] disableValue = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;

	return enable ? enableValue : disableValue;
}
 
Example 7
Source File: CharacteristicDetailActivity.java    From AndroidBleManager with Apache License 2.0 5 votes vote down vote up
private void checkProperty(int property){
    writeView.setVisibility(View.GONE);
    readView.setVisibility(View.GONE);
    notifyView.setVisibility(View.GONE);
    // 可读
    if ((property & BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
        readView.setVisibility(View.VISIBLE);
    }
    // 可写,注:要 & 其可写的两个属性
    if ((property & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) > 0
            || (property & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0) {
        writeView.setVisibility(View.VISIBLE);
    }
    // 可通知,可指示
    if ((property & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0
            || (property & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) {
        readView.setVisibility(View.VISIBLE);
        notifyView.setVisibility(View.VISIBLE);
        mNotifyList.setVisibility(View.VISIBLE);
        if ((property & BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
            mTvNotifyAndRead.setText("READ/NOTIFY VALUES");
        }
    }
    // 广播
    if ((property & BluetoothGattCharacteristic.PROPERTY_BROADCAST) > 0){
    }
}
 
Example 8
Source File: CharacteristicDetailsActivity.java    From BLEService with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static String getCharacteristicPropertiesString(int props) {
 String propertiesString = String.format("0x%04X [", props);
 if((props & BluetoothGattCharacteristic.PROPERTY_READ) != 0) propertiesString += "read ";
 if((props & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0) propertiesString += "write ";
 if((props & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) propertiesString += "notify ";
 if((props & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) propertiesString += "indicate ";
 if((props & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0) propertiesString += "write_no_response ";
 propertiesString += "]";
 return propertiesString;

}
 
Example 9
Source File: GattTransactionValidatorTest.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testAnythingOtherThanConnectWhileDisconnectedTransactionValidator() {
    conn.resetStates();
    GattStateTransitionValidator validator = new GattStateTransitionValidator();
    GattTransaction tx = new ReadGattCharacteristicMockTransaction(conn,
            GattState.READ_CHARACTERISTIC_SUCCESS,
            new BluetoothGattCharacteristic(UUID.randomUUID(),
                    BluetoothGattCharacteristic.PERMISSION_READ,
                    BluetoothGattCharacteristic.PROPERTY_INDICATE),
            new byte[] { 0x12, 0x14},
            false);
    GattStateTransitionValidator.GuardState guardState = validator.checkTransaction(conn.getGattState(), tx);
    Assert.assertEquals(GattStateTransitionValidator.GuardState.INVALID_TARGET_STATE, guardState);
}
 
Example 10
Source File: GattTransactionValidatorTest.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testSettingTransactionTimeout(){
    conn.resetStates();
    conn.setState(GattState.CONNECTED);
    WriteGattCharacteristicMockTransaction writeGattCharacteristicMockTransaction = new WriteGattCharacteristicMockTransaction(conn, GattState.WRITE_CHARACTERISTIC_SUCCESS, new BluetoothGattCharacteristic(UUID.randomUUID(),
            BluetoothGattCharacteristic.PERMISSION_READ,
            BluetoothGattCharacteristic.PROPERTY_INDICATE),
            new byte[] { 0x12, 0x14},
            false, 100L);
    Assert.assertEquals(100L, writeGattCharacteristicMockTransaction.getTimeout());
}
 
Example 11
Source File: ConnectionModule.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
@Provides
static CharacteristicPropertiesParser provideCharacteristicPropertiesParser() {
    return new CharacteristicPropertiesParser(BluetoothGattCharacteristic.PROPERTY_BROADCAST,
            BluetoothGattCharacteristic.PROPERTY_READ,
            BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE,
            BluetoothGattCharacteristic.PROPERTY_WRITE,
            BluetoothGattCharacteristic.PROPERTY_NOTIFY,
            BluetoothGattCharacteristic.PROPERTY_INDICATE,
            BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE);
}
 
Example 12
Source File: GattDatabase.java    From SweetBlue with GNU General Public License v3.0 4 votes vote down vote up
public final Properties indicate()
{
    m_properties |= BluetoothGattCharacteristic.PROPERTY_INDICATE;
    return this;
}
 
Example 13
Source File: Peripheral.java    From react-native-ble-manager with Apache License 2.0 4 votes vote down vote up
private void setNotify(UUID serviceUUID, UUID characteristicUUID, Boolean notify, Integer buffer,
		Callback callback) {
	if (!isConnected()) {
		callback.invoke("Device is not connected", null);
		return;
	}
	Log.d(BleManager.LOG_TAG, "setNotify");

	if (gatt == null) {
		callback.invoke("BluetoothGatt is null");
		return;
	}
	BluetoothGattService service = gatt.getService(serviceUUID);
	BluetoothGattCharacteristic characteristic = findNotifyCharacteristic(service, characteristicUUID);

	if (characteristic != null) {
		if (gatt.setCharacteristicNotification(characteristic, notify)) {

			if (buffer > 1) {
				Log.d(BleManager.LOG_TAG, "Characteristic buffering " + characteristicUUID + " count:" + buffer);
				String key = this.bufferedCharacteristicsKey(serviceUUID.toString(), characteristicUUID.toString());
				this.bufferedCharacteristics.put(key, new NotifyBufferContainer(key, buffer));
			}

			BluetoothGattDescriptor descriptor = characteristic
					.getDescriptor(UUIDHelper.uuidFromString(CHARACTERISTIC_NOTIFICATION_CONFIG));
			if (descriptor != null) {

				// Prefer notify over indicate
				if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) {
					Log.d(BleManager.LOG_TAG, "Characteristic " + characteristicUUID + " set NOTIFY");
					descriptor.setValue(notify ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
							: BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
				} else if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) {
					Log.d(BleManager.LOG_TAG, "Characteristic " + characteristicUUID + " set INDICATE");
					descriptor.setValue(notify ? BluetoothGattDescriptor.ENABLE_INDICATION_VALUE
							: BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
				} else {
					Log.d(BleManager.LOG_TAG, "Characteristic " + characteristicUUID
							+ " does not have NOTIFY or INDICATE property set");
				}

				try {
					registerNotifyCallback = callback;
					if (gatt.writeDescriptor(descriptor)) {
						Log.d(BleManager.LOG_TAG, "setNotify complete");
					} else {
						registerNotifyCallback = null;
						callback.invoke(
								"Failed to set client characteristic notification for " + characteristicUUID);
					}
				} catch (Exception e) {
					Log.d(BleManager.LOG_TAG, "Error on setNotify", e);
					callback.invoke("Failed to set client characteristic notification for " + characteristicUUID
							+ ", error: " + e.getMessage());
				}

			} else {
				callback.invoke("Set notification failed for " + characteristicUUID);
			}

		} else {
			callback.invoke("Failed to register notification for " + characteristicUUID);
		}

	} else {
		callback.invoke("Characteristic " + characteristicUUID + " not found");
	}

}
 
Example 14
Source File: Helper.java    From react-native-ble-manager with Apache License 2.0 4 votes vote down vote up
public static WritableMap decodeProperties(BluetoothGattCharacteristic characteristic) {

		// NOTE: props strings need to be consistent across iOS and Android
		WritableMap props = Arguments.createMap();
		int properties = characteristic.getProperties();

		if ((properties & BluetoothGattCharacteristic.PROPERTY_BROADCAST) != 0x0 ) {
			props.putString("Broadcast", "Broadcast");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_READ) != 0x0 ) {
			props.putString("Read", "Read");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0x0 ) {
			props.putString("WriteWithoutResponse", "WriteWithoutResponse");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0x0 ) {
			props.putString("Write", "Write");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0x0 ) {
			props.putString("Notify", "Notify");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0x0 ) {
			props.putString("Indicate", "Indicate");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0x0 ) {
			// Android calls this "write with signature", using iOS name for now
			props.putString("AuthenticateSignedWrites", "AuthenticateSignedWrites");
		}

		if ((properties & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) != 0x0 ) {
			props.putString("ExtendedProperties", "ExtendedProperties");
		}

//      iOS only?
//
//            if ((p & CBCharacteristicPropertyNotifyEncryptionRequired) != 0x0) {  // 0x100
//                [props addObject:@"NotifyEncryptionRequired"];
//            }
//
//            if ((p & CBCharacteristicPropertyIndicateEncryptionRequired) != 0x0) { // 0x200
//                [props addObject:@"IndicateEncryptionRequired"];
//            }

		return props;
	}
 
Example 15
Source File: P_DeviceServiceManager.java    From SweetBlue with GNU General Public License v3.0 4 votes vote down vote up
static BleDevice.ReadWriteListener.Type modifyResultType(BleCharacteristicWrapper char_native, BleDevice.ReadWriteListener.Type type)
{
	if( !char_native.isNull())
	{
		if( type == Type.NOTIFICATION )
		{
			if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0x0 )
			{
				if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0x0 )
				{
					type = Type.INDICATION;
				}
			}
		}
		else if( type == Type.WRITE )
		{
			if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0x0 )
			{
				if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0x0 )
				{
					type = Type.WRITE_NO_RESPONSE;
				}
				else if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0x0 )
				{
					type = Type.WRITE_SIGNED;
				}
			}
			//--- RB > Check the write type on the characteristic, in case this char has multiple write types
			int writeType = char_native.getCharacteristic().getWriteType();
			if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE)
			{
				type = Type.WRITE_NO_RESPONSE;
			}
			else if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_SIGNED)
			{
				type = Type.WRITE_SIGNED;
			}
		}
	}
	
	return type;
}
 
Example 16
Source File: P_DeviceServiceManager.java    From AsteroidOSSync with GNU General Public License v3.0 4 votes vote down vote up
static BleDevice.ReadWriteListener.Type modifyResultType(BleCharacteristicWrapper char_native, BleDevice.ReadWriteListener.Type type)
{
	if( !char_native.isNull())
	{
		if( type == Type.NOTIFICATION )
		{
			if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) == 0x0 )
			{
				if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0x0 )
				{
					type = Type.INDICATION;
				}
			}
		}
		else if( type == Type.WRITE )
		{
			if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) == 0x0 )
			{
				if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0x0 )
				{
					type = Type.WRITE_NO_RESPONSE;
				}
				else if( (char_native.getCharacteristic().getProperties() & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0x0 )
				{
					type = Type.WRITE_SIGNED;
				}
			}
			//--- RB > Check the write type on the characteristic, in case this char has multiple write types
			int writeType = char_native.getCharacteristic().getWriteType();
			if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE)
			{
				type = Type.WRITE_NO_RESPONSE;
			}
			else if (writeType == BluetoothGattCharacteristic.WRITE_TYPE_SIGNED)
			{
				type = Type.WRITE_SIGNED;
			}
		}
	}
	
	return type;
}
 
Example 17
Source File: GattDatabase.java    From AsteroidOSSync with GNU General Public License v3.0 4 votes vote down vote up
public final Properties indicate()
{
    m_properties |= BluetoothGattCharacteristic.PROPERTY_INDICATE;
    return this;
}
 
Example 18
Source File: GattDatabase.java    From SweetBlue with GNU General Public License v3.0 4 votes vote down vote up
public final Properties indicate()
{
    m_properties |= BluetoothGattCharacteristic.PROPERTY_INDICATE;
    return this;
}
 
Example 19
Source File: CorePeripheral.java    From RxCentralBle with Apache License 2.0 4 votes vote down vote up
@Nullable
private PeripheralError setCharacteristicNotification(
    BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic characteristic, boolean enable) {

  BluetoothGattDescriptor cccd = characteristic.getDescriptor(CCCD_UUID);
  if (cccd == null) {
    return new PeripheralError(PeripheralError.Code.SET_CHARACTERISTIC_NOTIFICATION_CCCD_MISSING);
  }

  if (!bluetoothGatt.setCharacteristicNotification(characteristic, enable)) {
    return new PeripheralError(PeripheralError.Code.SET_CHARACTERISTIC_NOTIFICATION_FAILED);
  }

  int properties = characteristic.getProperties();
  byte[] value;

  if (enable) {
    if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY)
        == BluetoothGattCharacteristic.PROPERTY_NOTIFY) {
      value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
    } else if ((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE)
        == BluetoothGattCharacteristic.PROPERTY_INDICATE) {
      value = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE;
    } else {
      return new PeripheralError(PeripheralError.Code.SET_CHARACTERISTIC_NOTIFICATION_MISSING_PROPERTY);
    }
  } else {
    value = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
  }

  characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);

  if (!cccd.setValue(value)) {
    return new PeripheralError(CHARACTERISTIC_SET_VALUE_FAILED);
  }

  if (!bluetoothGatt.writeDescriptor(cccd)) {
    return new PeripheralError(PeripheralError.Code.WRITE_DESCRIPTOR_FAILED, ERROR_STATUS_CALL_FAILED);
  }

  return null;
}
 
Example 20
Source File: BleConnectWorker.java    From Android-BluetoothKit with Apache License 2.0 4 votes vote down vote up
private boolean isCharacteristicIndicatable(BluetoothGattCharacteristic characteristic) {
    return characteristic != null && (characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0;
}