B4J Tutorial [BANano] Bidirectional communication between B4J and BANano

Hello,

I found something interesting from Daestrum and tried it out to see if it could be used for BANano.

With this code it is possible to establish a communication between a B4J WebView and a BANano App. You can call a BANano function from B4J and call a B4J function from BANano.

EZ73iAz.png


Maybe you will find this as useful as I do. :)

Greetings ... Peter
 

Attachments

  • B4JWebView.zip
    3 KB · Views: 521
  • BANanoWebView.zip
    1.2 KB · Views: 571

micro

Well-Known Member
Licensed User
Longtime User
Hi Kiffi
i make a test with your example but not work
In WebKit I changed this:
B4X:
'WebView1.LoadUrl("http://localhost/BANano/BANanoWebView/") ' <- adapt to your needs!
WebView1.LoadUrl("C:/inetpub/wwwroot/BANano/BANanoWebView/") ' <- adapt to your needs!

BANanoWebView is active and if i click on the button on the B4J form it's exit
This is the Error

B4X:
WebViewEngine.RunMethod("executeScript", Array As String("_banano_bananowebview.test4();"))

B4X:
Waiting for debugger to connect...
Program started.
Errore nella linea: 34 (Main)
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at b4j.example.main._btncalljsfunction_click(main.java:149)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$1.run(BA.java:216)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
Caused by: netscape.javascript.JSException: ReferenceError: Can't find variable: _banano_bananowebview
    at com.sun.webkit.dom.JSObject.fwkMakeException(JSObject.java:156)
    at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
    at com.sun.webkit.WebPage.executeScript(WebPage.java:1509)
    at javafx.scene.web.WebEngine.executeScript(WebEngine.java:1005)
    ... 27 more

Thanks
 
Top