Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android “什么是”呢;“可靠写入”;在英国?_Android_Bluetooth Lowenergy_Android Bluetooth - Fatal编程技术网

Android “什么是”呢;“可靠写入”;在英国?

Android “什么是”呢;“可靠写入”;在英国?,android,bluetooth-lowenergy,android-bluetooth,Android,Bluetooth Lowenergy,Android Bluetooth,在Android的BLEAPI()中,有一些方法可以处理可靠的写操作: public boolean beginReliableWrite () public void abortReliableWrite (BluetoothDevice mDevice) public boolean executeReliableWrite () 还有一个回调(在中): 我找不到这方面的任何文件。这是怎么一回事?它与“正常”(不可靠?)有什么不同 可靠写入允许检查传输值和一条或多条传输消息的原子执行

在Android的BLEAPI()中,有一些方法可以处理可靠的写操作

public boolean beginReliableWrite ()

public void abortReliableWrite (BluetoothDevice mDevice)

public boolean executeReliableWrite ()
还有一个回调(在中):


我找不到这方面的任何文件。这是怎么一回事?它与“正常”(不可靠?)有什么不同

可靠写入允许检查传输值和一条或多条传输消息的原子执行

有关可靠写入过程的详细说明,请参阅。尽管它是针对JavaScript的,
beginReliableWrite()
的描述尤其有助于理解该过程:

一旦启动了可靠的写事务,所有对 将characteristic.writeValue()发送到远程设备进行 验证并排队等待原子执行。承诺 携带响应于每个 writeValue()调用,应用程序负责 用于验证值是否已准确传输。之后 所有特征都已排队验证, ExecuteEliableWrite()将执行所有写入操作。如果一个特征 未正确写入,调用abortReliableWrite()将取消 当前事务,而不在远程LE上提交任何值 装置

你开始可靠的写作

gatt.beginReliableWrite();
设置特征值并将其写入

characteristic.setValue(value);
gatt.writeCharacteristic(characteristic);
writeCharacteristic()
调用将触发其“正常”回调。参数<代码>特性包含可验证的实际写入值:

@Override
public void onCharacteristicWrite(BluetoothGatt gatt,
                BluetoothGattCharacteristic characteristic, 
                int status) {
    ...

    if(characteristic.getValue() != value) { 
        gatt.abortReliableWrite();
    } else {
        gatt.executeReliableWrite();
    }

    ...
}

执行可靠写入将触发onReliableWriteCompleted(蓝牙gatt,int状态)回调。

characteristic.getValue()!=值不比较内容,而是比较数组的内存地址,这是错误的。无论如何,android中的可靠写入操作目前已被破坏,因为getValue()不返回服务器发送的值,这与文档所述相反。我们只需使用
.contentEquals()
修改特征值的比较即可
@Override
public void onCharacteristicWrite(BluetoothGatt gatt,
                BluetoothGattCharacteristic characteristic, 
                int status) {
    ...

    if(characteristic.getValue() != value) { 
        gatt.abortReliableWrite();
    } else {
        gatt.executeReliableWrite();
    }

    ...
}