I don't know why but the HttpJob class isn't calling the JobDone method when I run on a physical device using Debug (Legacy) mode. If I change it to Debug (Rapid) it works correctly.
B4X:
'Class module
Sub Class_Globals
Private tmrCheckInetConnection As Timer
Public IsConnected As Boolean = False
Private OrighowOften As Int
Private fastHowOften As Int = 8000
Public OnConnectedEvent As clsEvent
Public OnDisconnectedEvent As clsEvent
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(tmrHowOften2CheckMS As Int)
OrighowOften = tmrHowOften2CheckMS '--- save original value
tmrCheckInetConnection.Initialize("tmrCheckInetConnection",fastHowOften)
OnConnectedEvent.Initialize
tmrCheckInetConnection_Tick
End Sub
Private Sub JobDone (Job As HttpJob)
Dim oldConnected As Boolean = IsConnected
If Job.Success = True Then
IsConnected = True
ToastMessageShow("Checked internet - GOOD", True)
'Log("INet connected)
'--- we have a good connection so set to orig value
tmrCheckInetConnection.Initialize("tmrCheckInetConnection",OrighowOften)
'Previously it was not connected, so raise event that it is now connected
If (oldConnected = False) Then
OnConnectedEvent.Raise
End If
Else
IsConnected = False
ToastMessageShow("Checked internet - BAD", True)
Dim s As String = "Inet... Error: " & Job.ErrorMessage
g.LogWrite(s,g.ID_LOG_ERR)
g.ToastMessageShowx("Unable to connect to the internet", True)
'--- its not connected so set to every 8 sec
tmrCheckInetConnection.Initialize("tmrCheckInetConnection",fastHowOften)
'Previously it was connected so raise event that connection has been lost
If (oldConnected) Then
OnDisconnectedEvent.Raise
End If
End If
Job.Release
tmrCheckInetConnection.Enabled = True
End Sub
Private Sub tmrCheckInetConnection_Tick
'tmrCheckInetConnection.Enabled = False
Dim job1 As HttpJob
job1.Initialize("job1", Me)
job1.Download("http://www.google.com")
End Sub