當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE屬性代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:androidthings,項目名稱:sample-bluetooth-le-gattserver,代碼行數:25,代碼來源:GattServerActivity.java

示例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;
}
 
開發者ID:UDOOboard,項目名稱:UDOOBluLib-android,代碼行數:11,代碼來源:UdooBluService.java

示例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));
    }
}
 
開發者ID:inovait,項目名稱:neatle,代碼行數:68,代碼來源:SubscribeCommand.java


注:本文中的android.bluetooth.BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。