Sub Process_Globals
Dim WebView1 As WebView
End Sub
Sub Globals
Dim wvExtras As WebViewExtras
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("layout") ' Ensure this matches your layout file name
WebView1.Initialize("WebView1")
Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
wvExtras.Initialize(WebView1)
' Enable JavaScript in the WebView
wvExtras.addJavascriptInterface(WebView1, "B4A")
' Load some initial HTML or a webpage
WebView1.LoadUrl("https://www.example.com")
' Example: Writing to localStorage
wvExtras.ExecuteJavascript("localStorage.setItem('key', 'value');")
' Example: Reading from localStorage
Dim js As String
js = "var value = localStorage.getItem('key'); B4A.CallSub('ProcessValue', value);"
wvExtras.ExecuteJavascript(js)
End Sub
Sub WebView1_PageFinished (Url As String)
' Inject JavaScript here if you need to wait for the page to load
End Sub
' This Sub will be called from JavaScript
Sub ProcessValue(value As String)
Log("Received value from localStorage: " & value)
End Sub