Best way to check wifi connection

brelto85

Active Member
Licensed User
Longtime User
what is the best way to check if the wifi is connected?
in forum i found:

1.

B4X:
Sub Globals
     Dim MyLan As ServerSocket
End Sub

Sub CheckForWiFi
     If MyLan.GetMyIP = "127.0.0.1" Then  '
          Return False
     Else
          Return True
     End If
End Sub

2.

B4X:
Sub CheckWiFi
  Dim p As Phone  'Phone Library
  If p.GetSettings ("wifi_on") <> 1 Then
    MsgBox ("WiFi is OFF","")
      Else  'WiFi is on
        If p.GetDataState = "DISCONNECTED" Then ' Phone carrier's data network is disconnected
          MsgBox ("WiFi is ON and CONNECTED","")
            Else
        MsgBox ("WiFi is ON but NOT connected to a WiFi network","")
        End If                        
  End If
End Sub

are only these or there are another efficient methods to do that?
should be need to have a way that works for all devices.

thanks
alberto
 

supriono

Member
Licensed User
Longtime User
erel i have same trouble with wifi conection
fist conecton aplication work fine
but when i want to second conection server.conect("192.168.1.1",8080.2000) error

this if scenario test my aplication:
1. Conect to wifi AP (fine)
2. Disconect (fine)
3. Conect again to wifi (error/not responding)

B4X:
sub mnudisconect_click
server.close
astream.close
log("disconnet from wifi")
end sub

what should I do to fix this Erel??
sorry to disturb your work
thank you
 
Upvote 0
Top