Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 928
user1955086 Avatar asked Mar 03 '16 12:03

user1955086


People also ask

How do you send more than 20 bytes in BLE?

Sending more than 20 bytes via BLE is easily achievable by splitting your data into 20 byte packets and implementing a short delay (i.e. using sleep() ) between sending each packet.

How many BLE devices can Android connect?

x protocol SPEC, when the iPhone/Android phone play as role of BLE central mode, the limitation to have active connection at the same time is up to 8 devices.

How do I enable BLE on Android?

Use of the Bluetooth LE APIs requires you to declare several permissions in your manifest file. Once your app has permission to use Bluetooth, your app needs to access the BluetoothAdapter and determine if Bluetooth is available on the device. If Bluetooth is available, the device will scan for nearby BLE devices.


1 Answers

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?

like image 113
Ameer Avatar answered Dec 02 '22 03:12

Ameer