I'm trying to exchange data between android device and custom board with BLE module. And i have some troubles with characteristicsWrite() method on Android devices version 5.0 and higher. In lover versions characteristicsWrite() method return true and then calls onCharacteristicsWrite() callback in BleGattCallback
write method:
private void sendMessageToDevice(String message) {
byte nullByte = 0x00;
byte[] temp = message.getBytes();
byte[] tx = new byte[temp.length + 1];
tx[tx.length - 1] = nullByte;
System.arraycopy(temp, 0, tx, 0, temp.length);
characteristicWrite.setValue(tx);
boolean writeResult = mBluetoothGatt.writeCharacteristic(characteristicWrite);
Log.d(LOG_TAG, "writeResult"); //true
}
onCharacteristicsWrite method:
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicWrite(gatt, characteristic, status);
Log.d(LOG_TAG, status); // status = 0 - GATT_SUCCESS
}
But when i execute this code on android devices v 5.0 result of writeCharacteristic() method always false, and onCharacteristicWrite() callback not called.
Can anyone explain me how to properly establish connection between BLE device and Android 5.0+ ? Maybe i need some specific approach for this type of devices. Application tested on Samsung and Lenovo smartphones v5.0+.