I use this code to check if there is an internet connection:
Because of the GetDataState and GetSettings of the phone library, I think I need to use the dangerous permission READ_PHONE_STATE and get permission.
I found this other function (that uses non dangerous permission ACCESS_NETWORK_STATE):
My question is:
to avoid get the permission to check internet connection with the phone library, the second function is the best option?
B4X:
Sub CheckConnection As Boolean
Dim p As Phone
If (p.GetDataState == "CONNECTED") Then
Return True
End If
If (p.GetSettings ("wifi_on") == 1) Then
Return True
End If
If (p.GetDataState == "DISCONNECTED") Then
Return False
End If
If (p.GetDataState == "SUSPENDED") Then
Return False
End If
End Sub
Because of the GetDataState and GetSettings of the phone library, I think I need to use the dangerous permission READ_PHONE_STATE and get permission.
I found this other function (that uses non dangerous permission ACCESS_NETWORK_STATE):
B4X:
Sub CheckConnection As Boolean
Dim res As Boolean = False
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
r.Target = r.RunMethod("getActiveNetworkInfo")
If r.Target <> Null Then
res = r.RunMethod("isConnectedOrConnecting")
End If
Return res
End Sub
My question is:
to avoid get the permission to check internet connection with the phone library, the second function is the best option?