Android Question Bluetooth Admin & Target SDK 31

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I'm having an issue in my app with the StartDiscovery and DiscoveryFinished events firing twice, so I went back to basics with @Erel 's Bluetooth Example (https://www.b4x.com/android/forum/threads/android-bluetooth-bluetoothadmin-tutorial.14768/#content).

Download and run the example "as is" (targetSdkVersion="26", Release obfuscated, #BridgeLogger: True, in all of this) and it works fine on the device. Runtime permission is set for "while app is running" in both examples.

I change the manifest to TargetSdkVersion=31 as in my app, clean the project and run, and never fires any events after issuing .StartDiscovery whereas mine fires both start and finished twice.

Is there a step or RTP that I missed?

-- EDIT --
Ok, I missed the change from _COARSE_ to _FINE_ on the privilege, and once I changed that the example program worked as expected. Mine, however, is still having issues. I am quite certain that I invoke the .StartDiscovery method only once but it seems to be running internally twice (I added log statements to each event handler):
B4X:
** Activity (actsettingspaired) Resume **
Starting BT Discovery...
START BT Discovery...
START BT Discovery...
BT Device () FOUND AT (40:08:AA:56:2E:E7)
BT Device () FOUND AT (40:08:AA:56:2E:E7)
BT Device (IMP029-BL-US) FOUND AT (DC:0D:30:7C:51:28)
BT Device (IMP029-BL-US) FOUND AT (DC:0D:30:7C:51:28)
BT Device () FOUND AT (73:3B:9C:A7:3A:57)
BT Device () FOUND AT (73:3B:9C:A7:3A:57)
BT Device () FOUND AT (5E:9F:73:BB:32:F7)
BT Device () FOUND AT (5E:9F:73:BB:32:F7)
BT Device () FOUND AT (58:F8:A9:16:FD:5A)
BT Device () FOUND AT (58:F8:A9:16:FD:5A)
BT Device () FOUND AT (68:73:AF:B9:DB:BB)
BT Device () FOUND AT (68:73:AF:B9:DB:BB)
BT Device (IMP029-BL-US) FOUND AT (DC:0D:30:7C:51:28)
BT Device (IMP029-BL-US) FOUND AT (DC:0D:30:7C:51:28)
BT Device () FOUND AT (7E:8B:4E:9B:5F:60)
BT Device () FOUND AT (7E:8B:4E:9B:5F:60)
BT Device () FOUND AT (60:92:69:3D:22:BC)
BT Device () FOUND AT (60:92:69:3D:22:BC)
BT Device () FOUND AT (86:2A:FD:A1:68:CB)
BT Device () FOUND AT (86:2A:FD:A1:68:CB)
BT Device () FOUND AT (4E:63:5E:8A:31:A0)
BT Device () FOUND AT (4E:63:5E:8A:31:A0)
FINISHED BT Discovery...
FINISHED BT Discovery...
It seems to be providing each device twice in the Discovered event, as well as firing the start/finish twice.
 
Last edited:
Top