ABNumberOfAvailableWifiNetworks = 0 even though I can see many networks in wifi setti

jkurant

Member
Licensed User
Longtime User
ABNumberOfAvailableWifiNetworks is returning 0 even though I can see many networks in the phone's wifi settings.

this is my code:

Globals:
B4X:
Dim listNetworksVisible As ListView
Dim lblVisibleNetworks As Label
Dim wifi As ABWifi
When user changes tabs:

B4X:
listNetworksVisible.Clear
Dim r As Boolean
Dim a As Int
r = wifi.ABLoadWifi()
If r = True Then
   listNetworksVisible.AddSingleLine("Connected to: " & wifi.ABGetCurrentWifiInfo().SSID)
   listNetworksVisible.AddSingleLine("# of networks found: " & wifi.ABNumberOfAvailableWifiNetworks)
   For a = 0 To wifi.ABNumberOfAvailableWifiNetworks - 1
           listNetworksVisible.AddSingleLine(wifi.ABGetWifiNetwork(a).SSID & " " & wifi.ABGetWifiNetwork(a).Level)
   Next
Else
   listNetworksVisible.AddSingleLine(wifi.ABWifiLastError) 
End If

Can anyone tell me what is wrong?
 
Last edited:

NJDude

Expert
Licensed User
Longtime User
You need a "pause" after r = wifi.ABLoadWifi() to give time to the library to get the networks, you can use a timer for that.

Take a look at the attached sample.
 

Attachments

  • WiFi_Sample.zip
    6.2 KB · Views: 364
Upvote 0

foakgul

Member
Licensed User
Longtime User
Hello!

I've been experimenting with ABWifi as well and that's also what I noticed: The code needs pause for number of available networks to be populated but I don't think it's scalable to enter a hardcoded pause value ie 1000ms because for some networks (devices) it might take more. Is there a way to get around this using an event based trigger ie wait until number of available networks is at least 1? Native Java code achieves this without specifying any pause but I don't know how I can use this as a library in my B4A code.

Here's java code for scanning networks:
android - Wifi Scanning code - Stack Overflow

Thanks!
 
Upvote 0
Top