- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想订阅多个特征。目前我正在通过在调用每个 writeDescriptor(descriptor) 之间使用计时器来做到这一点(大部分成功)。我想改为使用 onDescriptorWrite() 回调来执行此操作,但它永远不会被调用。
我有以下回电。
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
broadcastUpdate(intentAction);
Log.i(TAG, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to start service discovery:" +
mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_DISCONNECTED;
mConnectionState = STATE_DISCONNECTED;
Log.i(TAG, "Disconnected from GATT server.");
broadcastUpdate(intentAction);
}
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
} else {
Log.w(TAG, "onServicesDiscovered received: " + status);
}
}
@Override
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
}
}
@Override
public void onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {
broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
}
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
super.onDescriptorWrite(gatt, descriptor, status);
Log.d("onDescWrite", "yes");
if(characteristics_with_notifications_or_indications.size() > 0) {
characteristics_with_notifications_or_indications.remove(0);
subscribeToCharacteristics();
}
}
};
它在我的连接函数中初始化。
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
这是我写的描述符
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString(CESGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
我想知道我何时通过回调完成 writeDescriptor() 操作,以便我可以订阅另一个特征。然而,即使我已经成功订阅了一个特性并收到了有效数据,onDescriptorWrite() 仍然没有被调用。我怎样才能让 onDescriptorWrite() 被调用?
最佳答案
所以我想通了这个问题。回调函数没有被调用,因为我有一个包含所有具有通知/指示属性的特征的列表。但是,在写入描述符之前,我会检查某些 UUID。好吧,我没有检查其中一个特性,因为我没有使用它,而它恰好是列表中的第一个!所以,我什至都不会写入要调用的回调的描述符。
关于java - onDescriptorWrite() 从未在 BluetoothGattCallback 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49641272/
背景 我最近在 merge 期间遇到了一个意外未 merge 的文档文件的问题。 无论出于何种原因,我搞砸了 merge 并有效地删除了文件(和其他几个文件),因为我忘记了它们的存在。 现在我想查看我
我在我的网站上使用旧的 mysql 版本和 php 版本 4。 我的表结构: | orders_status_history_id | orders_id | orders_status_id |
我是一名优秀的程序员,十分优秀!