Call Java function (Android) inside a hybrid mobile application with JavaScript

1

We are building a hybrid web application, which needs to print to a portable printer by bluetooth . But the printer is imported and only comes with a Java SDK, which is not our strong!

We needed to print from the JavaScript code, but I'm not sure if I can call the Java print functions or something like that. And the other alternative would be to create a plugin , which we are already working on but it will take a long time.

It is a mobile project, it will be created .apk and it is totally offline .

    
asked by anonymous 31.08.2016 / 22:17

1 answer

1

There is no direct way to do this because javascript will not have an API available in the browser that can speak directly to JDK.

However, javascript can easily make requests via Ajax, which uses HTTP. Then you create a Java application, which provides a REST API and publishes it in some IP: any port. The javascript application communicates with the java application using REST. The java application, in turn, is concerned with talking to the printer.

    
31.08.2016 / 22:23