Android Question BLE available devices on AsyncInputList

V. Solakis

New Member
Licensed User
Hi everyone,

could anyone provide please an example on how to list all detected (scanned) devices using BLE
to an AsyncInputList, so that the user can select the device that he/she wishes to connect to.

Thank you in advance,

V.S.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You mean InputListAsync.

Code in starter service:
B4X:
Sub Scan
   FoundDevices.Initialize 'process global Map variable
   manager.Scan2(Null, False)
   Sleep(10000)
   manager.StopScan
   CallSubDelayed2(Main, "AfterScan", FoundDevices)
End Sub


Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
   Log($"Device found: ${Name}"$)
   FoundDevices.Put(Name, Id)
End Sub

Code in Main:
B4X:
Sub AfterScan(Devices As Map)
   Dim items As List
   items.Initialize
   For Each name As String In Devices.Keys
     items.Add(name)
   Next
   If items.Size > 0 Then
     InputListAsync(items, "Select Device", 0, False)
     Wait For InputList_Result (Index As Int)
     If Index <> DialogResponse.CANCEL Then
       Dim id As String = Devices.Get(items.Get(Index))
       Log("Connect to: " & id)
     End If
   End If
End Sub
 
Upvote 0

V. Solakis

New Member
Licensed User
Wow!!!
Thank you very much Erel. I am much obliged.

Indeed, I meant InputListAsync.

Looking forward to test your code

V.S.
 
Upvote 0
Top