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] SP InetStatus - Check if Internet is available + type (WiFi/Cell/LAN)
(If you wish) you can view and/or modify the contents of the library. You are free to improve it if you find a way to do so. I only ask that you share your improvements with me so that I can share them with the B4X community to integrate them into this library. InetStatus Events...
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: