B4J Question Communicating between JavaScript in Webview to B4J

Derek Johnson

Active Member
Licensed User
Longtime User
In B4J I have a Webview with local HTML and I need to send a message from some JavaScript in the HTML to the B4J app. How can I do this?
 

Derek Johnson

Active Member
Licensed User
Longtime User
You can do this in B4A.

I'm beginning to think that I might need to set up a local web server to achieve what I want
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I'm beginning to think that I might need to set up a local web server to achieve what I want
It does not help.

I don´t know a way to do the same in B4J like in Android...
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
It does not help.

I don´t know a way to do the same in B4J like in Android...
The best I have managed to achieve is to submit a form to a server and to intercept the URL where I extracted the parameters. There were some oddities though; the server had to have a DNS record.
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
Thanks! I've got the example working now in Release mode. It took me a while to realise that I had to add ".main" to the package name in this bit of the code where it gets the class for the module:

/* With package name b4j.wvtest.x */
Class<?> c = Class.forName("b4j.wvtest.x.main");

I've now created a standalone package from the code. (I needed to add this property to make it build:
#PackagerProperty: IncludedModules = javafx.web

It then created my wvtest.exe file and the B4J to Webview comms worked as it should.

The Webview to B4J communication did not work though; nothing was received when I clicked either of the send buttons.

I then ran the standalone file using the .bat file and I saw the expected messages for the B4J to Webview action but there was nothing in the log when I clicked the send message button to send from the Webview to the B4J app.

Does anyone have any suggestions as to how what else might need changing?
 
Last edited:
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
I've now fixed the problem with the standalone app. It was caused I think by my code not waiting for the page to finish loading loading before referring the Java code.
 
Upvote 0
Top