本文整理匯總了Java中android.bluetooth.BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE屬性的具體用法?Java BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE怎麽用?Java BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.bluetooth.BluetoothGattDescriptor
的用法示例。
在下文中一共展示了BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDescriptorReadRequest
@Override
public void onDescriptorReadRequest(BluetoothDevice device, int requestId, int offset,
BluetoothGattDescriptor descriptor) {
if (TimeProfile.CLIENT_CONFIG.equals(descriptor.getUuid())) {
Log.d(TAG, "Config descriptor read");
byte[] returnValue;
if (mRegisteredDevices.contains(device)) {
returnValue = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
} else {
returnValue = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
}
mBluetoothGattServer.sendResponse(device,
requestId,
BluetoothGatt.GATT_FAILURE,
0,
returnValue);
} else {
Log.w(TAG, "Unknown descriptor read request");
mBluetoothGattServer.sendResponse(device,
requestId,
BluetoothGatt.GATT_FAILURE,
0,
null);
}
}
示例2: isNotificationEnabled
public boolean isNotificationEnabled(String mac, BluetoothGattCharacteristic characteristic) {
BluetoothGatt bluetoothGatt = checkAndGetGattItem(mac);
boolean result = false;
if (bluetoothGatt != null) {
BluetoothGattDescriptor clientConfig = characteristic.getDescriptor(GattInfo.CLIENT_CHARACTERISTIC_CONFIG);
if (clientConfig != null) {
result = clientConfig.getValue() == BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
}
}
return result;
}
示例3: start
@Override
protected void start(Connection connection, BluetoothGatt gatt) {
if (type == Type.UNSUBSCRIBE && connection.getCharacteristicsChangedListenerCount(characteristicUUID) > 0) {
NeatleLogger.d("Won't unsubscribe on " + characteristicUUID + " since it has registered listeners");
finish(CommandResult.createEmptySuccess(characteristicUUID));
return;
}
BluetoothGattService service = gatt.getService(serviceUUID);
if (service == null) {
finish(CommandResult.createErrorResult(characteristicUUID, SERVICE_NOT_FOUND));
return;
}
BluetoothGattCharacteristic characteristic = service.getCharacteristic(characteristicUUID);
if (characteristic == null) {
finish(CommandResult.createErrorResult(characteristicUUID, CHARACTERISTIC_NOT_FOUND));
return;
}
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG);
if (descriptor == null) {
finish(CommandResult.createErrorResult(characteristicUUID, DESCRIPTOR_NOT_FOUND));
return;
}
boolean turnOn;
byte[] valueToWrite;
switch (type) {
case Type.SUBSCRIBE_INDICATION:
NeatleLogger.d("Subscribing to indications on " + characteristicUUID);
valueToWrite = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE;
turnOn = true;
break;
case Type.SUBSCRIBE_NOTIFICATION:
NeatleLogger.d("Subscribing to notifications on " + characteristicUUID);
valueToWrite = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
turnOn = true;
break;
case Type.UNSUBSCRIBE:
NeatleLogger.d("Unsubscribing from notifications/indications on " + characteristicUUID);
valueToWrite = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
turnOn = false;
break;
default:
throw new IllegalStateException();
}
byte[] descriptorValue = descriptor.getValue();
if (Arrays.equals(descriptorValue, valueToWrite)) {
NeatleLogger.d("No subscription changes needed - is at " + valueToWrite[0] + " on " + characteristicUUID);
finish(CommandResult.createEmptySuccess(characteristicUUID));
return;
}
if (!gatt.setCharacteristicNotification(characteristic, turnOn)) {
NeatleLogger.e("Failed to change characteristics notification flag on " + characteristicUUID);
finish(CommandResult.createErrorResult(characteristicUUID, BluetoothGatt.GATT_FAILURE));
return;
}
descriptor.setValue(valueToWrite);
NeatleLogger.e("Writing descriptor on " + characteristicUUID);
if (!gatt.writeDescriptor(descriptor)) {
NeatleLogger.e("Failed to write descriptor on " + characteristicUUID);
finish(CommandResult.createErrorResult(characteristicUUID, BluetoothGatt.GATT_FAILURE));
}
}