B4A Library [B4X] BLE 2 - Bluetooth Low Energy

Not open for further replies.
This library replaces the previous BLE library.
It is simpler to use and it is more powerful. Its API is based on B4i iBLE library which makes it easy to reuse B4i code.

See the iBLE tutorial: https://www.b4x.com/android/forum/threads/ble-bluetooth-low-energy-library.46099/#content

Tips & Notes

- You can call Manager.Scan2 with AllowDuplicates set to True if you want to monitor the state of an unconnected device.
- The AdvertisingData map in DeviceFound event holds pairs of integers as keys (data types) and bytes arrays as values.
- Call ReadData2 if you are only interested in a single characteristic.
- BLE is only supported on Android 4.3+.

See the attached example. Note that the important code in in the Starter service module.


A new version of BLE_Example was uploaded. targetSdkVersion is now set to 29
Setting the targetSdkVersion to 29 requires some changes:

1. Add the fine location permission in the manifest editor.
2. Request this permission with RuntimePermissions.

Otherwise scanning will fail with a message visible in the unfiltered logs.

BLE2 is an internal library now. It is included in the IDE.

Example is based on B4XPages and will work with B4A and B4i.


  • BLEExample.zip
    181.5 KB · Views: 1,643
Last edited:

Angel Maza

Licensed User
Longtime User

Have you seen slower connection in BLE2 library??. In my app, BLE library connect is in 1-3 secs. With BLE2 depends between 3 and 30 seconds, or even not at all connection in some cases (not distance related).

I've seen that scan_stop before connect improves timings, but even with scan_stop the BLE2 connect is far slower than BLE.
Not open for further replies.