Fennec Native UI 101
Margaret Leibovic
April 25, 2012
Margaret Leibovic
April 25, 2012
Create a GeckoEvent in Java:
GeckoAppShell.sendEventToGecko( GeckoEvent.createBroadcastEvent("MessageToJS", "data"));
Add an observer in JS:
Services.obs.addObserver(observer, "MessageToJS", false);
Your listener just needs to implement nsIObserver
Create a JSON message in JS:
let message = { gecko: { type: "MessageToJava", ... } }; sendMessageToJava(message);
Register a listener in Java:
GeckoAppShell.registerGeckoEventListener("MessageToJava", listener);
Your listener just needs to implement GeckoEventListener:
public interface GeckoEventListener { public void handleMessage(String event, JSONObject message); }