Android Question (RESOLVE) HTML page B4A.CallSub

sigster

Active Member
Licensed User
Longtime User
Hi


I just upload the project , I am try to select the point in the map but it don't work

any tips how I can do this
 

Attachments

Last edited:
Try this simple test - the function call works for me
B4X: Copy
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    
    Private WebView1 As WebView
    Dim WebViewExtras1 As WebViewExtras
    Private JavascriptInterface1 As DefaultJavascriptInterface

End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("lQuest")
    
    WebViewExtras1.Initialize(WebView1)
    JavascriptInterface1.Initialize
    WebViewExtras1.addJavascriptInterface(JavascriptInterface1, "B4X")
    
'    WebView1.LoadUrl(".....")
    WebView1.LoadHtml(File.ReadString(File.DirAssets, "endquest.html"))

End Sub

'Receives a sub to call from js
Public Sub CallOK
'    Starter.kvs.Put("quest", False)
    B4XPages.ClosePage(Me)
End Sub

in endquest.html
HTML: Copy
....
<button onclick="callB4aOK()">OK</button>
    
script:
    function callB4aOK(){
       // Second parameter must be TRUE.. read WebviewExtras documentation @ https://www.b4x.com/android/forum/threads/webviewextras.12453/
        B4X.CallSub("CallOK", true);
    }
 
Upvote 0
Try this simple test - the function call works for me
B4X: Copy
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
   
    Private WebView1 As WebView
    Dim WebViewExtras1 As WebViewExtras
    Private JavascriptInterface1 As DefaultJavascriptInterface

End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("lQuest")
   
    WebViewExtras1.Initialize(WebView1)
    JavascriptInterface1.Initialize
    WebViewExtras1.addJavascriptInterface(JavascriptInterface1, "B4X")
   
'    WebView1.LoadUrl(".....")
    WebView1.LoadHtml(File.ReadString(File.DirAssets, "endquest.html"))

End Sub

'Receives a sub to call from js
Public Sub CallOK
'    Starter.kvs.Put("quest", False)
    B4XPages.ClosePage(Me)
End Sub

in endquest.html
HTML: Copy
....
<button onclick="callB4aOK()">OK</button>
   
script:
    function callB4aOK(){
       // Second parameter must be TRUE.. read WebviewExtras documentation @ https://www.b4x.com/android/forum/threads/webviewextras.12453/
        B4X.CallSub("CallOK", true);
    }
Thanks for the help :)
 
Upvote 0
When I compile the app on my work computer, it works, but when I compile it on my private computer, it doesn't work
Has anyone encountered a problem like this ?


B4X: Copy
  WebViewExtras1.Initialize(WebView1)
    JavascriptInterface1.Initialize
    WebViewExtras1.addJavascriptInterface(JavascriptInterface1, "B4X")
    
'    WebView1.LoadUrl(".....")
    WebView1.LoadHtml(File.ReadString(File.DirAssets, "endquest.html"))
 
Upvote 0
The html B4X.CallSub work if I compile in Release but not when I compile in Release (obfuscated)

Thanks again Jerryk
 
Upvote 0
Back
Top