user1955086
user1955086

Reputation: 141

Reading More then 20 byte from remote BLE device failed in Lollipop

We are facing one issue when reading characteristics from remote BLE device.

This issue happen in Android OS 5.0 and above.

Points are below to generate issue :

  1. Make one peripheral device with one service and one characteristics.
  2. Characteristics will have only read permission. Now set the value of this characteristics with more than 20 characters i.e. 20 bytes.
  3. Now let peripheral device broadcast itself with one service and one characteristics.
  4. Now launch any BLE scanner app from market and connect with this peripheral device.
  5. Once successfully connected with peripheral device just try to read characteristics.
  6. In this case it will not show any data and when debugging the app it show that it returns null data.
  7. The above same case not working in the Android OS 5.0 and above.
  8. Same case working in android 4.4.

So there is something change in Android OS 5.0 and above that internally disable readblob() request that can read data having more that 20 characters.

Upvotes: 8

Views: 2749

Answers (1)

Ameer
Ameer

Reputation: 2769

This can be simply achievable by splitting your data into 20 byte packets and implementing a short delay (i.e. using sleep()) between sending each packet.

You can use BluetoothGatt.requestMtu(). See the Official document of BluetoothGatt.requestMtu

     Request an MTU size used for a given connection. 
       When performing a write request operation (write without response), the data       
sent is truncated to the MTU size. This function may be used to request a larger MTU size to be able to send more data at once.

A onMtuChanged(BluetoothGatt, int, int) callback will indicate whether this operation was successful.

Requires BLUETOOTH permission.

If you want send more 20 bytes, you should define array byte[] include how many packet you want. There is an example Android: Sending data >20 bytes by BLE

Also there is another example How to send more than 20 bytes data over ble in android?

Upvotes: 1

Related Questions