'Activity module
Sub Process_Globals
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")
Activity.AddMenuItem("Save webpage", "SaveWebpage")
' add the B4A javascript namespace to the WebView
WebViewExtras1.addJavascriptInterface(WebView1, "B4A")
' now load a web page
WebView1.LoadUrl("http://www.b4x.com/forum/index.php")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub WebView1_PageFinished (Url As String)
' This Sub is called each time a new web page has been loaded in WebView1
' http://www.b4x.com/android/wiki/index.php/WebView#PageFinished_.28Url_As_String.29
Log("WebView1_PageFinished")
Log("Webpage Url: "&Url)
Dim Javascript As String
Javascript="B4A.CallSub('WebView1_SaveWebPage', true, '"&Url&"', document.documentElement.outerHTML)"
Log("Javascript to execute: "&Javascript)
' When WebView1 executes the Javascript it will get the web page content and call the Sub WebView1_SaveWebPage passing the web page Url and content as Strings
WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub
Sub WebView1_SaveWebPage(Url As String, PageContent As String)
' WebView1 will call this Sub via the B4A Javascript interface
Log("WebView1_SaveWebPage")
Log("Webpage Url: "&Url)
Log("Webpage Content: "&PageContent)
' Log may truncate a large page so you'll not see all of the HTML in the log but the PageContent String will still contain all of the web page content
Log("Now you now want to save PageContent")
End Sub
Sub SaveWebpage_Click
Dim Javascript As String
Javascript="B4A.CallSub('WebView1_SaveWebPage', true, '"&WebView1.Url&"', document.documentElement.outerHTML)"
WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub