SOLUTION HERE
Please do not use the following code in your projects.
Below I share a function that returns if the Internet connection exists and what type of connection is available.
Warning: @drgottjr wrote to me: The classes and methods used for b4a have all been deprecated for some time (since sdk 28/29)
[B4X] Check if Internet interfaces are enabled and internet status + type (WiFi/Cell/LAN)
This project combines two libraries, [B4X] SP Ping and [B4X] IFStatus. The following code shows how to use both libraries. https://www.b4x.com/android/forum/threads/b4x-sp-ping-run-the-ping-command-from-b4a-b4j-and-b4i.161861/...
www.b4x.com
Please do not use the following code in your projects.
Below I share a function that returns if the Internet connection exists and what type of connection is available.
Warning: @drgottjr wrote to me: The classes and methods used for b4a have all been deprecated for some time (since sdk 28/29)
Code Module:
Sub Process_Globals
Type tpeCheckInternet(blnIsOnline As Boolean, strType As String)
End Sub
Public Sub CheckInternet() As tpeCheckInternet
Dim ci As tpeCheckInternet
ci.Initialize
ci.strType = "NONE"
ci.blnIsOnline = False
Dim jo As JavaObject
jo.InitializeContext
Dim cm As JavaObject = jo.RunMethod("getSystemService", Array("connectivity"))
Dim activeNetwork As JavaObject = cm.RunMethod("getActiveNetworkInfo", Null)
If activeNetwork.IsInitialized Then
If activeNetwork.RunMethod("isConnected", Null).As (Boolean) = True Then
ci.blnIsOnline = True
If activeNetwork.RunMethod("getType", Null).As (Int) = 1 Then
ci.strType = "WIFI"
Else
ci.strType = "CELL"
End If
End If
End If
Return ci
End Sub
Usage Example Code:
Sub Class_Globals
Dim tpeInet As tpeCheckInternet
End Sub
Public Sub Initialize
tpeInet.Initialize
End Sub
Private Sub B4XPage_Appear
'Check if the connection is active
If tpeInet.blnIsOnline Then
If tpeInet.strType = "WIFI" Then
'Download the large file automatically
Else
'Wait for user approval to use cellular network data
End If
Else
'No internet connection available
End If
End Sub
Last edited: