Customizations and Extensions / Use front calls |
Genero applications can call native Android methods.
Genero applications can call native Android methods. The GHC uses a JavaScriptâ„¢ API class named GHCJavascriptAPI that lets JavaScript methods call native methods. JavaScript will use the object instance created by the JavaScript API class given to the webview to call native methods.
For ease of use, developers call this class method by another function, gwc.ghc.invoke('functionName', params). It needs a function name and a JSON object as parameters.
... function setMyGeneroApplicationName() { var data = {}; data.name = 'Application name'; data.description = 'some description'; gwc.ghc.invoke('setGeneroApplicationName', data); } ...
public class GHCJavascriptAPI { ... public void setGeneroApplicationName(String vArgs, String vCallbackId) { String args = null; String name = null; String description = null; // Decode URI and remove quotes try { args = URLDecoder.decode(vArgs, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { JSONObject jsonObject = new JSONObject(args); name = jsonObject.getString("name"); description = jsonObject.getString("description"); } catch (JSONException e) { e.printStackTrace(); } ... } ... }