Android Question Link in WebView calls B4A subroutine?

canalrun

Well-Known Member
Licensed User
in B4A I currently dynamically create a small, simple webpage (as a string, s1) and load it into a WebView using: wv.LoadHtml(s1).

Is it possible, as I'm creating the webpage, to create a link within the webpage that when clicked will cause the B4A program to call a subroutine?

(The B4A subroutine I'm thinking about will restore marker points from a file and display them on a map)

Nothing too complicated.

Thanks,
Barry.
 

HAH

Well-Known Member
Licensed User
or simply use webview override event and consume it.
 

canalrun

Well-Known Member
Licensed User
or simply use webview override event and consume it.
Thanks. That works very well.

In my html file I embedd a link:

B4X:
<a href="reload:xxxx">Reload</a>
When I click on the link the following code runs (my WebView is named wvSession):

B4X:
Sub wvSession_OverrideUrl (Url As String) As Boolean
  If (Url.IndexOf("reload:") > -1) Then
    Dim id As String = Url.SubString2(7, Url.Length)
    
    Log("id: " & id)
    ReloadSession(id)
    
    Return(True)
  End If
End Sub

Sub ReloadSession(id As String)
  Dim slst As List
 
  slst = File.ReadList(File.DirDefaultExternal, "Sessions.txt")
 
  For Each s1 As String In slst
    If ((s1.Contains("<!--")) And (s1.Contains(id))) Then
      Log("found id: " & s1)
    End If
  Next
End Sub
I am looking for an html comment line that contains the "id" in the file Sessions.txt.

Barry
 

HAH

Well-Known Member
Licensed User
Your code appears to be fine, is it working? is Log("found id: " & s1) executed?
 

canalrun

Well-Known Member
Licensed User
Yes, works very well.

I dynamically generate a "session" and append it to a file called Sessions.txt. Each "session" is an exercise session. The session block contains parameters such as ID, duration, laps, and time, plus I repeat the parameters in an HTML comment comma separated string that can later be restored to the screen display to remind me of that exercise session. I restore the session by clicking the dynamically generated link (containing the session ID) that is saved as part of the session block.

Thanks for the idea.
 
Last edited:
Top