Android Question WebViewExtras example

gezueb

Active Member
Licensed User
Longtime User
I tried the original example by Warwound. It compiles after changing the WebViewExtras1 to a single parameter and the app shows the forum post alright. However, the
Sub ProcessHTML(Html As String)
never gets called and therefore no log is produced.


B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: SaveHTML
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #BridgeLogger: true
#End Region

'Activity module
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 WebViewExtras1 As WebViewExtras
    Dim WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("layoutMain")
    WebViewExtras1.Initialize(WebView1)
    '    add the B4A javascript interface to the WebView
    WebViewExtras1.addJavascriptInterface(WebView1, "B4A")
    
    '    now load a web page
    WebView1.LoadUrl("http://www.basic4ppc.com/forum/additional-libraries-classes-official-updates/12453-webviewextras.html#post70053")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub WebView1_PageFinished (Url As String)
    '    Now that the web page has loaded we can get the page content as a String
    
    '    see the documentation http://www.basic4ppc.com/forum/additional-libraries-classes-official-updates/12453-webviewextras.html#post70053 for details of the second parameter callUIThread
    
    Dim Javascript As String
    Javascript="B4A.CallSub('ProcessHTML', false, document.documentElement.outerHTML)"
    

    Log("PageFinished: "&Javascript)
    WebViewExtras1.ExecuteJavascript(Javascript)
'    WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub

Sub ProcessHTML(Html As String)
    '    This is the Sub that we'll get the web page to send it's HTML content to
    
    '    Log may truncate a large page so you'll not see all of the HTML in the log but the 'html' String should still contain all of the web page HTML
    
    Log("ProcessHTML: "&Html)
End Sub
 

drgottjr

Expert
Licensed User
Longtime User
1) webviewextras1 is not initialized
2) webviewextras1.executejavascript() takes 2 parameters: WebViewExtras1.ExecuteJavascript(WebView1, Javascript). you had the correct statement commented out.

i have no trouble running your example.
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Thanks, however I do initialize webviewextras1 in line 29 in actvity create and my compiler throws an error with two parameters in WebViewExtras1, thats why i commented it out. I use the latest WebViewExtras2 lib version 2.20. Maybe thats the problem? What version do you load?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i load good, old, trusted webviewextras. executing javascript with webviewextras2 should work; you're just using it incorrectly (evidently). although the 2 libraries were written by the same person, they operate differently. i've never had occasion to use webviewextras2. sorry.
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Ok, I tried with your trusted ? webviewextra V1.42 and indeed it works. FYI, there is no initialization method for it. Thank you!
 
Upvote 0
Top