Android Question WebView

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hi @Erel !

Is it possible to hide a WebView if getting an error (Page Not Found... no connection, etc) - i mean, detect an error event and take an action...

Thanks!
 

mc73

Well-Known Member
Licensed User
Longtime User
You can use the webView_pageFinished sub, then call a js using webViewExtras and read the content. Depending on the error, you'll get a different content. Check this post.
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
You can use the webView_pageFinished sub, then call a js using webViewExtras and read the content. Depending on the error, you'll get a different content. Check this post.

Hi @mc73 !

thanks for answering... I really discovered a solution based on webviewextras... check the pagetitle! The only problem is the language: in portuguese devices (I´m brazilian) the Web site not found title is "Página da web não disponível"... we can live with this but should exist a solution based in http communication/signalling ... that should be more "elegant"...

Regards.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
I have a new version of WebViewExtras that supports the onReceivedError callback.

Take a look at this example code:

B4X:
Sub Process_Globals

End Sub

Sub Globals
   Dim WebView1 As WebView
   Dim WebViewExtras1 As WebViewExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)
   WebView1.Initialize("")
   Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
   
   WebViewExtras1.Initialize(WebView1)
   
   Dim WebViewClient1 As DefaultWebViewClient
   WebViewClient1.Initialize("WebViewClient1")
   
   WebViewExtras1.SetWebViewClient(WebViewClient1)
   
   WebViewExtras1.LoadUrl("http://gooXle.co.uk/")   '   deliberate typo!
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebViewClient1_ReceivedError(ErrorCode As Int, Description As String, FailingUrl As String)
   Log("WebViewClient1_ReceivedError "&ErrorCode)
   '   the WebView will still display 'Web page not available' until we (successfully) load another web page
   WebViewExtras1.LoadUrl("http://google.co.uk/")   '   comment this line and you'll see the 'Web page not available'
End Sub

You can download the latest version of WebViewExtras2 from here: http://android.martinpearman.co.uk/b4a/temp/WebViewExtras2_20131012.zip.
Inside that download is WebViewExtras2.html, take a look at the DefaultWebViewClient and you'll see the various Fileds named ERROR_???? that can help you establish which error has occurred.

If you are currently using the old WebViewExtras and need help updating to WebViewExtras2 then let me know - you cannot use both the old and new version in the same project.

Martin.
 
Upvote 0
Top