I am using the bellow function to test internet connection and works ok
B4X:
Public Sub testInternet(url as String) As ResumableSub
Dim result As Boolean = False
Dim Job As HttpJob
Job.Initialize("Job", Me)
Job.Download(url)
Log ("Sending job")
Wait For(Job) JobDone(Job As HttpJob)
If Job.Success Then
result = True
Log("Success")
Else
result = False
Log("No connection...")
End If
Job.Release
Return result
End Sub
But now i want app not to do anything until Internet will be available so i did this
B4XMainPage:
Dim rst As Boolean = False
Do While rst = False
Wait for(testInternet("the url i want to test e.g. google.com")) Complete (rst As Boolean)
Loop
When true it continues but when internet not available it does some work for a few tries but without waiting success continues the app and then the app crash.
I'm working on about 3 hours.
It is working very well but i have to change many things in my code. For now i create a function runOnce in MainPage and moved all code from B4XPage_Create and then i call them from _Appear as your example. One strange thing is that i lost AddMenuItems at the first run. When i return to mainPage from other page they are in their place.
Usually it is placed in the B4XPage_Created for this reason but since first there is the Internet check I wanted to avoid loading the layout and then running the check but it is possible to load the layout also in the B4XPage_Created, it was just my choice.
No, I haven't found a way to disable a menu, not even by acting directly on the Activity.
For now you can use a boolean variable (for example: Dim InternetAvailable As Boolean), check its value inside the menu click event and exit the event (immediate return) if it is False.
No, I haven't found a way to disable a menu, not even by acting directly on the Activity.
For now you can use a boolean variable (for example: Dim InternetAvailable As Boolean), check its value inside the menu click event and exit the event (immediate return) if it is False.
Private Sub B4XPage_Appear
mInternetAvailable = False
CheckInternet.ParentView = Root
Wait For (CheckInternet.Check(True)) Complete(Result As Boolean)
Dim Toast As BCToast
Dim Msg As String = "Internet enabled = " & Result
Toast.Initialize(Root)
Toast.Show(Msg)
Log(Msg)
If Result Then
mInternetAvailable = True
ContinueHere
Else
ExitApplication
End If
End Sub
B4X:
Private Sub B4XPage_MenuClick (Tag As String)
If Not(mInternetAvailable) Then Return
ToastMessageShow("menu", False)
End Sub
You made me open the pc again!
Interesting code. So we can bypass menus by checking if boolean mInternetAvailable is false.
Good idea. I 'll check it tomorrow.
Thank you again and goodnight.
Finaly, all checks made. Application works thanks to your lib.
Menus disabled as you proposed by checking if internet active or not.
Thank you very much.