pcplayer99 11 Posted December 19, 2019 Android, Delphi 10.3.3. community version. TBluetoothLE scan BLE device ok, and then: var AService: TBluetoothGattService; AService := BluetoothLE1.GetService(Self.FMyDevice, Service_ID); if not Assigned(AService) then raise exception.Create('No service found.'); Here, mybe I can got the service, mybe not, on the same device. Maybe I restart APP and can got service. Share this post Link to post
Lars Fosdal 1792 Posted December 19, 2019 Did you call BluetoothLE1.DiscoverServices before calling GetService? http://docwiki.embarcadero.com/Libraries/Rio/en/System.Bluetooth.TBluetoothLEDevice.GetService http://docwiki.embarcadero.com/Libraries/Rio/en/System.Bluetooth.TBluetoothLEDevice.DiscoverServices 1 Share this post Link to post
pcplayer99 11 Posted December 20, 2019 Thank you Lars. My Program is: 1. Scan device. then list devices. 2. Let user select a device, and user click a "Select" button. 3. in the button onclick event handler, find the device, and set user selected device to FMyDevice, and then call BluetoothLE1.DiscoverServices(Self.FMyDevice); 4. Do someting that need service, call GetService(FMyDevice), and then maybe ok, maybe got nil. Share this post Link to post
Rollo62 536 Posted December 22, 2019 You may need to give Android a little time after setting one command, before it will be able to give back a result. Also you should always ensure to touch such commands and results into the UI thread, as these responses came from extenral devices, and may drop in at any (asynchronous) time. The whole Bluetooth system is quite tricky, and has various smaller or larger pitfalls on different platforms. Share this post Link to post
pcplayer99 11 Posted December 22, 2019 thanks. I will test add some minutes waitting in every step. Share this post Link to post
pcplayer99 11 Posted December 22, 2019 Thanks Rollo62. I have tested, if I wait a minute and then do GetService, it's works fine. Share this post Link to post
pcplayer99 11 Posted December 22, 2019 After BluetoothLE1.OnEnddiscoverService triggered, Can always getService success. Share this post Link to post