Internet connection check

johnaaronrose

Active Member
Licensed User
Longtime User
I'm using HttpUtils2Service & Httpjob to download a file from the internet and I'm later using Google Maps, in my app. This file / a Google map could either come through the phone's data network or wifi network. I would like to check that there is a working connection made to the internet. I noticed GetDataState for the Phone object could be used to check the phone's connection. Is there a similar facility to check for a wifi connection having been made?
 

johnaaronrose

Active Member
Licensed User
Longtime User
Success


Thanks, Margret. I used code (in Click event for a button) as below to check if device connected to internet either by phone's data connection or wifi. Also, accepts emulator.

B4X:
Dim ph As Phone
   Dim myLAN As ServerSocket
   If ph.GetDataState <> "CONNECTED" _
   AND myLAN.GetMyIP = "127.0.0.1" Then
      Msgbox("Ensure that your Device" & CRLF & _
             "is Data Connected by Phone" & CRLF & _
             "or is WiFi Connected." & CRLF & _
               "And then try again.", _
                "No Internet Connection")
      Return
   End If
 
Last edited:
Upvote 0
Top