10.2 Tokyo handles BLE discovery on Android differently than 10.1 Berlin.
(My apologies for this lengthy entry)
I have had some problems getting BLE to work according to my needs on both iOS and Android, but after some work arounds (see my comment and issues on quality.embarcadero.com: RSP 16891, 17763, and 17764) things have worked quite well (although BLE on iOS seems more stable than on Android).
Having switched to Tokyo, However, I have had to revise my handling of BLE device discovery, and I wonder if anyone else has noticed this change, if my original way of handling things (which was convenient) was fundamentally wrong, and/or if the behavior on Tokyo is as intended and by design or a bug.
In my application, I often need to "rediscover" a BLE device that was "defined" a long time ago (often in a previous app session). I handle this by storing the device name and MAC address so that I quickly can run discovery using a TBluetoothLEScanFilterList with the proper LocalName and DeviceAddress at some later point in time when I need to communicate with the device.
Using Berlin, I simply used a procedure like InitializeMyDevice below where BluetoothLE1 is a TBluetoothLE, FMyBleDevice is a TBluetoothLEDevice, and BluetoothLE1 has an OnDiscoverLEDevice = BluetoothLE1DiscoverLEDevice. Everything works fine: if the device is found, descovery stops immediately; if not, discovery times out.
Using Tokyo, however, the same code doesn't work:
1. during Application.ProcessMessages the bleMainDiscoverLEDeviceis never called and the discovery always times out;
2. after timeout and exit of InitializeMyDevice all calls to bleMainDiscoverLEDeviceis do occur, but this is "too late".
Of course, this issue can be circumvented using, e.g., a second procedure to capture the result, but the "Berlin" method was quite simple and convenient.
So, hopefully some of you can have a look at the code below and explain to me what's going on!
Thanks in advance /Per
// Double check
if ((ADevice.DeviceName = MyDeviceName) and (ADevice.Address = MyMacAddress)) then
FMyBleDevice := ADevice;
function InitializeMyDevice: Boolean;
LBleFilterList := TBluetoothLEScanFilterList.Create;
LBleScanFilter := TBluetoothLEScanFilter.Create;
LBleScanFilter.LocalName := MyDeviceName;
LBleScanFilter.DeviceAddress := MyMacAddress;
FMyBleDevice := nil;
while (FMyBleDevice = nil) do
Result := (FMyBleDevice = nil);
More Follow UP: I have installed the Toolchain HotFix for 10.2 and it still will NOT discover any BLE devices. I then installed the 6/23/17 Android patch and still will NOT discover any BLE devices. Will be filling an issue report in the quality central now.
On a different computer I have installed 10.1 (update2) and 10.2 (No Hotfix). No additional options were installed on either one except what was available in the installation menu. So they are clean installations. Win32, Win64 and Android were installed. On the10.1 compiler the BLE project complies, installs and runs, finding all available BLE devices. Using the exact same project in 10.2, the project complies, installs and runs, except it does not find any BLE devices. The OnDiscoveryEnd event does fire, but it returns no BLE devices.
So now I am at a loss to understand this. Any help would be greatly appreciated.
I have also experienced that after changing to 10.2, BTLE discovery is not working anymore in Android. I am using the framework and calling
It does return TRUE and the OnDiscoveryEnd event does fire, but no devices are found. I have used the HeartRate sample and it does find the BTLE device, but it is using the BTLE Component, which looks like a major change for me.
I was just wondering if you ever solved your problem. Thanks and good luck with your development.
UPDATE: Actually I have to use the Framework, since part of my app is in a service and UI is not allowed in a service.