Android Question B4X for connection check

luke2012

Well-Known Member
Licensed User
Longtime User
Hi all,
within my B4X (only mobile Android & iOS) app (that get data using REST API) I need to check if it is an internet connection before continue.

Searching the forum I found this interesting [B4X][B4XLib] by @LucaMs.
just to my knowledge, is it the only solution within the B4X framework to check the connection without having to write the code from scratch?
 

josejad

Expert
Licensed User
Longtime User
I think Erel recommends just trying the connection and if it fails just show some kind of message. i.e.: “there was some problem connecting to the source. Are you connected to internet?”
 
Last edited:
Upvote 0

pliroforikos

Active Member
Licensed User
Hi all,
within my B4X (only mobile Android & iOS) app (that get data using REST API) I need to check if it is an internet connection before continue.

Searching the forum I found this interesting [B4X][B4XLib] by @LucaMs.
just to my knowledge, is it the only solution within the B4X framework to check the connection without having to write the code from scratch?
I m using this lib and it is very helpful without any problem. You can use google or other website to check it. I can say that checking with google.com is a little bit slow process to receive answer so use other webpage.
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
@José J. Aguilar and @pliroforikos thanks for your suggestions.
So I have to choose which is the best approach for my B4XPages app (Android & iOS).

basically, in my app, there are several places where this code is called:

B4X:
    Dim j As HttpJob : j.Initialize("j", Me)
    j.Username = aUser
    j.Password = aPsw
    Private WSUrl As String = WSNodeURL & nid & WSFormat
    j.Download (WSUrl)
    
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Private WSResponse As String = j.GetString2("UTF8")
    End If
    j.Release

So to prevent errors (ex. iOS Airplane mode) in my case I can handle this within else of "If j.Success Then", I guess.

so I have to then apply this across all occurrences of this code within my app, I guess.
 
Upvote 0

luke2012

Well-Known Member
Licensed User
Longtime User
B4X:
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Private WSResponse As String = j.GetString2("UTF8")
    else
        'msg 4 connection error
    End If

In my case, the problem is that the above code is within a non UI class (clsGlobals) so I can't do this:

B4X:
    toast.Initialize(Root)
    toast.VerticalCenterPercentage = 50
    toast.Show($"there was some problem connecting to the source"$)

So in my case, maybe this speech is not implementable?
 
Upvote 0
Top