I know this has been brought up a couple times on the forum, but I wanted to get an opinion on my code.
I considered using the ABWiFi library but it added a fine location permission, which is undesirable to me.
What I am trying to accomplish is:
1) Detect if WiFi is enabled
2) Detect if WiFi is connected to a network
This works here on my EVO 4G on Sprint, but I want to ensure that it should work "universally".....
It probably isn't completely foolproof but I think for most people there should be three states:
WiFi on and connected
WiFi on and not connected (and therefore phone is connected to carrier's data connection)
WiFi off and phone is connected to carrier's data connection
Mostly I care if WiFi is on and connected.
I considered using the ABWiFi library but it added a fine location permission, which is undesirable to me.
What I am trying to accomplish is:
1) Detect if WiFi is enabled
2) Detect if WiFi is connected to a network
This works here on my EVO 4G on Sprint, but I want to ensure that it should work "universally".....
B4X:
Sub Globals
Dim MyLan As ServerSocket ' Network Library - for detecting IP
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime then MyLan.Initialize(0, "")
End Sub
Sub Activity_Resume
If MyLan.IsInitialized Then CheckWiFi
End Sub
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
It probably isn't completely foolproof but I think for most people there should be three states:
WiFi on and connected
WiFi on and not connected (and therefore phone is connected to carrier's data connection)
WiFi off and phone is connected to carrier's data connection
Mostly I care if WiFi is on and connected.