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 :
- Make one peripheral device with one service and one characteristics.
- Characteristics will have only read permission. Now set the value of this characteristics with more than 20 characters i.e. 20 bytes.
- Now let peripheral device broadcast itself with one service and one characteristics.
- Now launch any BLE scanner app from market and connect with this peripheral device.
- Once successfully connected with peripheral device just try to read characteristics.
- In this case it will not show any data and when debugging the app it show that it returns null data.
- The above same case not working in the Android OS 5.0 and above.
- 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.
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.
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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With