This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Writing to a Characteristic using the Android 4.3 API

I am having a lot of trouble using the new 4.3 Android API. I am trying to develop an application for the Android that will communicate via BLE to a Nordic device. I have based my application on the example UART project provided by Nordic:

www.nordicsemi.com/.../nRF-UART-2.0-for-Android-4.3

After analyzing this code, I thought that I had figured out how to successfully write to a characteristic. The function, "writeRXCharacteristic()" does exactly this. But when I used nearly identical code in my program, it is extremely inconsistent. I say inconsistent instead of not working because it DOES work sometimes. There are times when I can connect to the Nordic device, select the proper characteristic, and write to it. Albeit a not very fast transaction, but it works on occasion. But if I disconnect from the device, and reconnect, the write may or may not work. I have even completely re-installed the app, (without changing any code on the app or Nordic) and it has about ~20% of working. I have no idea why this could be happening. If anyone has any idea what this could be, please let me know! I have been having troubles with this for some time, and I can't find a pattern as to why it is so seemingly random.

Here is the code I am using to send the characteristic:

[b]public void writeCharacteristic(byte[] value) { BluetoothGattService LumService = mBluetoothGatt.getService(UUID_LUM_APP); if (LumService == null) { System.out.println("LumService null"); return; } BluetoothGattCharacteristic LumChar = LumService.getCharacteristic(UUID_LUM_CHAR); if (LumChar == null) { System.out.println("LumChar null"); return; } LumChar.setValue(value); boolean status = mBluetoothGatt.writeCharacteristic(LumChar); System.out.println("Write Status: " + status); }[/b]

If there is any additional information I can provide, please let me know. Thanks in advance!

Related