Please use the BLE2 library instead: https://www.b4x.com/android/forum/threads/ble-2-bluetooth-low-energy.59937/
Android 4.3 adds support for Bluetooth Low Energy. This library allows you to access the new API. It allows you to search for BLE devices, connect to a device and read its services and characteristics.
Writing is currently not supported though it should be simple to add this feature.
From my testings BLE is not yet ready for production
It is unreliable. I also tested it with Google example app and the results were the same.
Seems like others have encountered such issues as well:
http://code.google.com/p/android/issues/detail?id=58381
http://stackoverflow.com/questions/17870189/android-4-3-bluetooth-low-energy-unstable
In order to use this library you will need to download platform level 18 from Android SDK and configure the IDE (Tools - Configure Paths) to use it.
Simple code that starts searching when you click on the activity:
Android 4.3 adds support for Bluetooth Low Energy. This library allows you to access the new API. It allows you to search for BLE devices, connect to a device and read its services and characteristics.
Writing is currently not supported though it should be simple to add this feature.
From my testings BLE is not yet ready for production
It is unreliable. I also tested it with Google example app and the results were the same.
Seems like others have encountered such issues as well:
http://code.google.com/p/android/issues/detail?id=58381
http://stackoverflow.com/questions/17870189/android-4-3-bluetooth-low-energy-unstable
In order to use this library you will need to download platform level 18 from Android SDK and configure the IDE (Tools - Configure Paths) to use it.
Simple code that starts searching when you click on the activity:
B4X:
Sub Process_Globals
Dim manager As BleManager
Private cs As List
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
manager.Initialize("ble")
Log("Supported: " & manager.BleSupported)
End If
End Sub
Sub Activity_Click
Log("Searching for devices")
manager.Scan(10000, Null)
End Sub
Sub ble_DeviceFound (Name As String, MacAddress As String)
Log(Name & ", " & MacAddress)
manager.Connect(MacAddress, True)
End Sub
Sub BLE_Connected (Services As Map)
cs.Initialize
Dim s As BleService = Services.GetValueAt(0)
'Read the manufacturer characteristic
Dim c As BleCharacteristic = s.GetCharacteristics.Get("00002a00-0000-1000-8000-00805f9b34fb")
manager.ReadCharacteristic(c)
End Sub
Sub BLE_CharacteristicRead (Success As Boolean, Characteristic As BleCharacteristic)
Log("CR: " & Success & ": " & Characteristic.Uuid)
If Success Then Log("cr: " & Characteristic.GetStringValue(0))
End Sub
Sub ble_Disconnected
Log("Disconnected")
End Sub
Sub ble_DiscoveryFinished
Log("DiscoveryFinished")
End Sub
Attachments
Last edited: