0

Could anybody suggest me how to approach this problem.

I am looking to establish bidirectional communication between a jquery mobile application on phonegap and a java server.

Can a pub/sub communication be established?

Is there someway to use JMS?

I have tried websockets, but I feel it lacks control, ie: I was not able to find a way to list the number of connected clients on the server etc.. It could be because of my lack of knowledge in web sockets, but web sockets look under developed to me.

any suggestions.

Thank you

user1479589
  • 315
  • 1
  • 4
  • 16

2 Answers2

0

PhoneGap is built upon the system web view for all platforms that are supported... The best you can do inside of the web view is web sockets (where supported), or a short interval poll. If that doesn't suit, you can create a native plugin to leverage native code/native communication libraries from your JS-based app. The catch is that the native plugins must be written in native code (obj-c for iOS, java for Android, etc...) and are not cross platform, but it can be done. You can read more about native plugins here: http://docs.phonegap.com/en/2.0.0/guide_plugin-development_index.md.html#Plugin%20Development%20Guide

Andrew Trice
  • 701
  • 5
  • 8
0

Bidirectional communication can be achieved with Cordova mechnisms underlying PhoneGap. For this you should write your own plugin.

Communication from JavaScript to the native App is fairly straightforward and documented here: https://cordova.apache.org/docs/en/5.0.0/guide_hybrid_plugins_index.md.html#Plugin%20Development%20Guide
The main point is to use the cordova.exec() method which triggers the corresponding function in your plugin.

The communication from native to JavaScript is documented here: how to send data or message from java application / plugin to javascript with cordova / phonegap

You can always execute javascript from java doing this:

String js = "alert('test')"; webView.loadUrlNow("javascript:" + js);

Or you can init the plugin and keep the callback doing this

PluginResult pgRes = new PluginResult(PluginResult.Status.OK, "message"); pgRes.setKeepCallback(true); callbackContext.sendPluginResult(pgRes);

Community
  • 1
  • 1
Benjamin Mesing
  • 4,075
  • 1
  • 18
  • 22