Android Question B4X - Consistently Determine if WIFI is available and connected - B4i, B4J, B4A


Well-Known Member
Licensed User
Longtime User
I tried this code (Along with a lot of other things but this works for all three)
    Dim IP As ServerSocket
    Dim myIp As String = IP.GetMyIP
    Return myIp

All return a valid looking IP if they are connected. However if I turn off the WIFI on each device, or don't connect to a router I get the following.

B4J: fe80:0:0:0:9d4c:3fa6:46:857%wlan0

Initializing ServerSocket makes no difference and as I understand it is not necessary to get the ip.
I seem to vaguely remember from my bouts with wifi a few years ago on android. That meant you were not connected. But now I get

So, my question is really this:
Is this the code I should be using to verify that the user is connected to a network and if so,
What do I look for to know when they are not connected?
B4i I think I get - if it is then not connected.
B4J - Do I parse it to see if it is in valid ipv4 format?
B4A I am lost. Is the new for android?

Thanks for your help.


Licensed User
The best way is to not make any test and just try to connect. If it works it works and if not then there is no valid connection.
I was trying to connect and the interface froze in the event of a sudden disconnect (Ethernet).I have enabled unmonitor network.
Upvote 0


Well-Known Member
Licensed User
B4A I am lost. Is the new for android?
The so-called Loopback address is a special IP number ( that is designated for the software loopback interface of a machine. The loopback interface has no hardware associated with it, and it is not physically connected to a network. It's purpose is and it is always available to reroute a network packet back to the sender without any change. It has nothing to or any relation to the connect status of your wifi interface.
The address could be a defined or retrieved network address of the wifi interface. Be aware that some driver software assign a valid privet 192.168.x.y address to a not connected wifi interface.
As always Erel has given the right answer:
If it works it works and if not then there is no valid connection.
Upvote 0