Android Question Internet Toggle Not working as expected

AndroidMadhu

Active Member
Licensed User
Hello,
I am checking the internet connectivity whether my Fleet App is connected to internet or not.
If I am on Mobile data App working fine. But while I am toggle to WiFi connectivity the Internet stops working.[But App is Running]
The same way If Initially I am at WiFi the App and Internet Working fine. The time when I am toggling to Mobile data [While the App is running] the App checking the Internet properly, but the internet is not working.
I have to crash the App and then restarting the Application. Then It is working.

The below is the code base I have written for Internet checking....

B4X:
Sub Globals
Public PhoneEvent1 As PhoneEvents
End Sub

Sub PhoneEvent_ConnectivityChanged(NetworkType As String, State As String, Intent As Intent)
      
'NetworkType - WIFI or MOBILE.
'State - One of the following values: CONNECTING, CONNECTED, SUSPENDED, DISCONNECTING, DISCONNECTED, UNKNOWN.
      
If State = "CONNECTED" Then
internetConnectionStatus(False,"")
Starter.internet_connected=True
Else
internetConnectionStatus(True,"No Internet. Connect Wi-Fi or Mobile Network")
Starter.internet_connected=False
Starter.mqttConnected=False
End If

Sub internetConnectionStatus(flag As Boolean,message As String)
Try
pnlInternet.Visible=flag
pnlInternet.BringToFront
lblConnection.Text=message
Catch
Log(LastException)
End Try
End Sub

Please advice why the Internet is not working properly while toggling to WiFi or Vice Versa.

Thanks
 

AnandGupta

Expert
Licensed User
Longtime User
Hi AndroidMadhu

It was answered somewhere that you need to fetch url like 'www.google.com' and check it, for wifi connection.
(I can not find the thread now)

Regards,

Anand
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…