I am developing BLE in Android , I can scan, connected and write characteristic to to the BLE device.
I call the following function to pass BluetoothGatt
and characteristic
to AsyncTask
when click the Button
.
write_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new WriteCharacteristic(mBluetoothGatt , HueCharacteristic).execute();
}
});
The code of write characteristic is like the following:
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;
}
}
But I try to click the button consecutive, it seems the Android did not write every characteristic
to the BLE device.
If I click the button consecutive for 5 times , it will loss 1~3 times. It only write characteristic
to BLE device for two times.
Question:
Is there any better way to write characteristic consecutive and stable to BLE device for Android?