小编bte*_*n96的帖子

更改蓝牙低能量gatt超时或刷新读取流以更快地检测断开事件

我正在寻找一种方法来刷新应用程序从Ble设备接收的特征,或者至少从数据中知道连接已经丢失,除非它在断开连接后大约15秒.如果有办法改变gatt连接超时,那将会更好.

要以不同的形式重复,我想要一个解决方案(或一个可以解释的链接)来检测BLE设备的断开速度比当前的超时值更快,通过查看我得到的值是否是新的通过刷新特性,或改变gatt侧的断开超时,所以我可以看到它在一秒内断开连接以触发其他代码.

android bluetooth-lowenergy gatt

6
推荐指数
1
解决办法
3437
查看次数

Android BluetoothGatt setCharacteristicNotification仅设置第一个特性

我通过相同的蓝牙LE设备同时使用两种不同的特性时遇到了问题.它只记录第一个特征而不是第二个特征.如果我切换它们,它仍然会记录第一个,但不是第二个.第一和第二特征都需要注册和接收.如果它有帮助,我使用运行4.4.2的三星Galaxy S4.

以下是调用setCharacteristicNotification()的代码部分

if (mBluetoothBeaconGatt != null && mBluetoothBeaconGatt.getService(UUID_CUSTOM_SERVICE) != null) {

        characteristicBracelet = mBluetoothBeaconGatt.getService(UUID_CUSTOM_SERVICE)
                .getCharacteristic(UUID_CUSTOM_BRACELET);

        characteristicBeacon = mBluetoothBeaconGatt.getService(UUID_CUSTOM_SERVICE)
                .getCharacteristic(UUID_CUSTOM_BEACON);

        if(characteristicBracelet != null) {
            Log.i(TAG, "Init Bracelet Characteristics");
            this.setCharacteristicNotification(characteristicBracelet,
                    true);
        }
        if(characteristicBeacon != null) {
            Log.i(TAG, "Init Beacon Characteristics");
            this.setCharacteristicNotification(characteristicBeacon, true);
        }
    }
Run Code Online (Sandbox Code Playgroud)

setCharacteristicNotification

if (UUID_CUSTOM_BEACON.equals(characteristic.getUuid())) {
        if (mBluetoothBeaconGatt != null) {
            Log.i(TAG, "Enabling indication for beacon");
            mBluetoothBeaconGatt.setCharacteristicNotification(characteristic, enabled);
            BluetoothGattDescriptor descriptor = characteristic
                    .getDescriptor(UUID
                            .fromString(CustomGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
            descriptor
                    .setValue((enabled) ? BluetoothGattDescriptor.ENABLE_INDICATION_VALUE
                            : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
            mBluetoothBeaconGatt.writeDescriptor(descriptor);
        }
    } else if (UUID_CUSTOM_BRACELET.equals(characteristic.getUuid())) {
        if (mBluetoothBraceletGatt …
Run Code Online (Sandbox Code Playgroud)

android bluetooth gatt

2
推荐指数
1
解决办法
6619
查看次数

标签 统计

android ×2

gatt ×2

bluetooth ×1

bluetooth-lowenergy ×1