#Region Internet Connection
Sub Test_Internet_Connection()
Dim p As Phone
Dim overall_data_state As Int
Dim cellular_data_state As Int
'0 Disabled - 1 Enabled. May also return a 3 in enabled state but I can find no explanation of the return values
'Note: Turning on airplane mode is not the same as disabling wifi
Dim wifi As Int = p.GetSettings ("wifi_on")
'Msgbox("Wi-Fi value is: " & wifi, "")
Dim airplane_mode As Int = p.GetSettings ("airplane_mode_on")
'Msgbox("Airplane mode value is: " & airplane_mode, "")
'Test the Cellular State
Select Case p.GetDataState
Case "CONNECTED"
cellular_data_state = 1
Case Else
'Captures the other possible states of "SUSPENDED" "DISCONNECTED" "CONNECTING"
cellular_data_state = 0
End Select
'Check to see if airplane_mode is enabled. 1 means device is in airplane_mode, 0 means device is not in airplane_mode
If airplane_mode = 1 Then
'We know for sure the internet is disconnected
overall_data_state = 0
Else
'Otherwise we know that the device is not in airplane_mode so check wifi and cellular
If wifi = 0 AND cellular_data_state = 0 Then
'Both the cellular and WiFi are disabled so we cannot have a connection (except some kind of tethering over blue-tooth)
overall_data_state = 0
Else
'Either Wifi or cellular is active so it is possible to have a connection
overall_data_state = 1
End If
End If
'Test the connection if it is possible to have one
If overall_data_state = 1 Then
'Initially indicate that we do have a connection and the screen label will probably be correct.
'We do this because of the potential latency in determining when a connection is not available.
Internet_Connected(True)
'Now we will test the connection and change it back to False if it fails
Dim job1 As HttpJob
job1.Initialize("Job1", Me)
'Send a GET request
job1.Download("http://www.google.com")
'Once this completes the JobDone routine is executed and the labels are set to their true state.
Else
Internet_Connected(False)
End If
End Sub
Sub JobDone (job As HttpJob )
If job.Success = True Then
Internet_Connected(True)
Else
Internet_Connected(False)
End If
job.Release
End Sub
Sub Internet_Connected (Flag As Boolean)
If Flag = True Then
InternetConnected = True
lblInternetConnected.Text = Chr(ConnectedIcon)
lblInternetConnected.TextColor = Colors.White
Else
InternetConnected = False
lblInternetConnected.text = Chr(DisconnectedIcon)
lblInternetConnected.TextColor = Colors.Red
End If
End Sub
#End Region