Android Question WebViewExtras2 version 2.20 sample codes

Erick Kalugdan

Member
Licensed User
I can't seem to find an example on how to use the ReceivedError event of the WebViewExtras2 library.

I tried to use it to replace WebViewExtras (the old one) but I am getting a lot of errors. They seem to have different methods and ways of initializing.

Can anyone help please? An example on the following would be of great help for everyone trying to use the new WebViewExtras2 (version 2.20) library.

a. How to load a URL
b. How to check if there is error 404
c. How to execute Javascript in the WebView
d. How Javascript in the WebView can call a Sub in B4A

Thanks in advance! :)
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Erick Kalugdan

Member
Licensed User
Was able to initialize, load URL, and execute a javascript in a WebView.

My remaining problem now is addJavascriptInterface doesn't seem to work with version 2.20. It's not calling the app's Sub's when I execute:

B4X:
<script>
function closeApp() {
 APP.CallSub("Logout", true);
}
</script>

Here's my app code:

B4X:
Sub Globals
    Dim LogonUrl As String = "file:///android_asset/test.htm"
    Dim WebView1 As WebView
    Dim WebViewExtras1 As WebViewExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)
    WebView1.Initialize("WebView1")
    Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
    WebView1.ZoomEnabled = False
    WebViewExtras1.Initialize(WebView1)
    WebViewExtras1.addJavascriptInterface(WebView1, "APP")
    WebView1.LoadUrl(LogonUrl)
End Sub

Sub Logout
    Activity.Finish
End Sub
 
Upvote 0

Erick Kalugdan

Member
Licensed User
I am using WebViewExtras2 version 2.20, not WebViewExtras version 1.42

Your code works with 1.42 but in 2.20 the IDE sends an error: Unknown member: addWebChromeClient
 
Upvote 0

Erick Kalugdan

Member
Licensed User
1. Does the ChromeClient have anything to do with the addJavascriptInterface? I just need my javascript to be able to run Sub's in my app just like version 1.42 does with CallSub

2. I believe the ChromeClient is only used for the logs? :)
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
So, still no solution for working addJavascriptInterface in v.2.20 ?
It works in Android < 4.4, but still no in 4.4+
 
Upvote 0
Top