我正在 Android 中开发 BLE,我可以扫描、连接并将特征写入 BLE 设备。
当单击. _ BluetoothGatt
_characteristic
AsyncTask
Button
write_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new WriteCharacteristic(mBluetoothGatt , HueCharacteristic).execute();
}
});
写特性的代码如下:
private class WriteCharacteristic extends AsyncTask<String, Void, String> {
public BluetoothGatt mGatt;
public BluetoothGattCharacteristic mCharacteristic;
public WriteCharacteristic(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic){
mGatt = gatt;
mCharacteristic = characteristic;
}
@Override
protected String doInBackground(String... urls) {
mGatt.writeCharacteristic(mCharacteristic);
return null;
}
}
但是我尝试连续单击按钮,似乎Android没有将every写入characteristic
BLE设备。
如果我连续点击按钮 5 次,它将丢失 1~3 次。它只写入characteristic
BLE设备两次。
问题:
Is there any better way to write characteristic consecutive and stable to BLE device for Android?