Android Question WebView Error 404 or ERR_ADDRESS_UNREACHABLE

leandroavila74

Member
Licensed User
Longtime User
Hello,
I would like to intercept error 404 or ERR_ADDRESS_UNREACHABLE when using the webview, I do not know how to do it, I looked in the forum and I followed the several examples
But none worked so I would like to know if someone can please help me, my code is simple:

B4X:
#Region  Project Attributes
    #ApplicationLabel: mobiPedido
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: True
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim WebView1 As WebView
    Dim WebAddress As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("webnav")
    WebAddress = "http://app.mobipedido.com.br/mobipedido.dll/m?telefone=5123456789"
    'Endereco = "http://192.168.15.14:8080/m?telefone=5123456789"   
    ProgressDialogShow2("C o n e c t a n d o ...",True)
    WebView1.LoadUrl(WebAddress)      
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Dim I As Int
        i = Msgbox2("Tem certeza que deseja sair do aplicativo?", "Sair do aplicativo", "SIM", "NÃO", "", Null)
        If i = DialogResponse.POSITIVE Then Return False
        If i = DialogResponse.NEGATIVE Then Return True
    Return True      
  End If
End Sub

Sub WebView1_PageFinished (Url As String)
  ProgressDialogHide
End Sub

Could you tell me how I could do to intercept these errors?, I have no idea how to do this :(
 
Last edited:

eurojam

Well-Known Member
Licensed User
Longtime User
you can send a get request with httputils before and check the result, something like:
B4X:
sub check_http
  Dim job1 As HttpJob
    job1.Initialize("Job1", Me)
   'Send a GET request
   job1.Download("http://www.freiburg.de/gusto/index.html")

End Sub


Sub JobDone (job As HttpJob)
   Log("JobName = " & job.JobName & ", Success = " & job.Success)
   If job.Success = False Then
      Log("Error: " & job.ErrorMessage)
      'do something else
   Else
       Log(job.GetString)
       'do something if ok         
   End If
   job.Release
End Sub
 
Upvote 0

leandroavila74

Member
Licensed User
Longtime User
Below I'll put my code with the solution presented by the friend "eurojam", I'm putting the complete code to help someone who
Have the same question I had, now my little application has been much better.

Thanks a lot for the help

B4X:
    #Region  Project Attributes
    #ApplicationLabel: mobi Pedido
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: True
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim WebView1 As WebView
    Dim WebAddress As String
    Private btnFechar As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    WebAddress = "http://app.mobipedido.com.br/mobipedido.dll/m?telefone=5123456789"
    'WebAddress = "http://192.168.15.14:8080/m?telefone=5123456789"
    ProgressDialogShow2("C o n e c t a n d o Aguarde...",True)
    check_http
End Sub

Sub check_http
    Dim job1 As HttpJob
    job1.Initialize("Job1", Me)
    'Send a GET request
    job1.Download(WebAddress)
End Sub

Sub JobDone (job As HttpJob)
    Log("JobName = " & job.JobName & ", Success = " & job.Success)
    If job.Success = False Then
        Log("Error: " & job.ErrorMessage)
        'do something else
        ProgressDialogHide
        Activity.LoadLayout("weberror")
    Else
        Log(job.GetString)
        'do something if ok
        Activity.LoadLayout("webnav")
        WebView1.LoadUrl(WebAddress)
    End If
    job.Release
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Dim I As Int
        i = Msgbox2("Tem certeza que deseja sair do aplicativo?", "Sair do aplicativo", "SIM", "NÃO", "", Null)
        If i = DialogResponse.POSITIVE Then Return False
        If i = DialogResponse.NEGATIVE Then Return True
    Return True   
  End If
End Sub

Sub WebView1_PageFinished (Url As String)
    ProgressDialogHide
End Sub

Sub btnFechar_Click
  Activity.Finish
End Sub
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Please use CODE TAG when posting code!
 
Upvote 0
Top