问题描述
我正在尝试订阅 9 个不同的同步特征通知。 我的目标和最小 SDK 版本是 23
我的应用目前最多只能订阅 5 条通知,然后停止。但是,在使用 nRF Connect 应用程序时,我可以手动订阅所有 9 个。
订阅的 5 个特征正确触发了 onCharacteristicChanged()
回调。
numNotifications = 8;
public void setNotify(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic){
boolean registered = gatt.setCharacteristicNotification(characteristic,true);
if(registered){
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID_DESCRIPTOR);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(descriptor);
}
numNotifications--;
}
在为第 9 个特征调用 setNotify()
后,我一次异步写入描述符一个特征。 (是的,我知道我可以使用循环而不是开关,并尝试使用相同的结果)。
@Override
public void onDescriptorWrite(BluetoothGatt gatt,BluetoothGattDescriptor descriptor,int status) {
// Called when the descriptor is updated for notification
if (status == BluetoothGatt.GATT_SUCCESS) {
switch (numNotifications){
case 7: setNotify(gatt,chars.get(numNotifications));
break;
case 6: setNotify(gatt,chars.get(numNotifications));
break;
case 5: setNotify(gatt,chars.get(numNotifications));
break;
case 4: setNotify(gatt,chars.get(numNotifications));
break;
case 3: setNotify(gatt,chars.get(numNotifications));
break;
case 2: setNotify(gatt,chars.get(numNotifications));
break;
case 1: setNotify(gatt,chars.get(numNotifications));
break;
case 0: setNotify(gatt,chars.get(numNotifications));
break;
}
}
}
问题:
- 是否有更好的方式订阅所有 9 个特征?
- 是不是因为我的设备(Samsung A30s 2019)只能处理 5 个订阅 - 如果是这样,nRF Connect 如何做更多?
- 如果是我的设备,也许我可以在与 @Emil 在这里提到的同一应用程序中创建 2 个 BluetoothGatt 对象:Android Bluetooth Low Energy Characteristic notification count limit: does this vary by device? 我该怎么做?
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)