B4A Library [B4X][B4XLib] B4XCheckInternetLM

Very simple cross-platform library to test if an Internet connection is active.

It has only one method, Check:
B4X:
Public CheckInternet As B4XCheckInternetLM

Wait For (CheckInternet.Check(True)) Complete(Result As Boolean)
If Result Then
'
Else
'
End If
Set the DialogToo parameter to False if you just want to test the presence of an active Internet connection, to True if you want to show a B4XDialog that gives the user time to activate one or "abort" the operation.

To test, the library downloads the page https://google.com. A different address can be set via the URL property.

It exposes the properties for the B4XDialog texts:

DlgTitle
DlgMsg
DlgYesText
DlgCancelText


and the B4XDialog itself, so you can change its appearance.

Library and B4XPages example attached.

V. 1.10
Added an indispensable property :confused: to set the Root of the current B4XPages open (name: ParentView)

I am also attaching a second example, which has two B4XPages, just to show that the new property is indispensable and how to use it.
 

Attachments

  • B4XCheckInternetLM_1_1_ex.zip
    16.1 KB · Views: 80
  • B4XCheckInternetLM.b4xlib
    1 KB · Views: 21
Last edited:

bobbruns

Member
Licensed User
Could not get this to work with B4i. Both my local server and the hosted server failed. Basic algorithm worked fine, and pasting it in place ok, but the library did not work.
I cannot find the dependant library iOkHttpUtils2

got this:
ld: library not found for -liOkHttpUtils2
clang: error: linker command failed with exit code 1 (use -v to see invocation)


Error: ** BUILD FAILED **
 

bobbruns

Member
Licensed User
I used the following, lifted almost exactly from this library:

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Wait For(checkinternet) complete(Result As Boolean)
    Log("result: " & Result)
End Sub

Private Sub checkinternet() As ResumableSub
    Dim URL As String = "https://www.google.com"
    Dim result As Boolean = False
    Dim Job As HttpJob
    Job.Initialize("Job", Me)
    Job.Download(URL)
    Wait For(Job) JobDone(Job As HttpJob)
    result = Job.Success
    Job.Release
    Return result
End Sub

Disadvantage of this method:
uses more bandwidth

Advantage of this method:
By changing the URL, I can check whether an older device can connect to the server of my choice. I am particularly worried about migration to newer TLS certificate standards where ipad production/OS version may have preceeded the development of the standard in use. (I know just throw that old ipad/tab away!) People keep their old devices far too long, and I don't want to get the phone call where they blame my app for their inability to connect to a TLS1.2 encrypted page.
 
Top