how to communicate an android activity with javascript code and vise versa in phonegap android? -
i new phonegap development. want's know how communicate our phonegap webpage native android activity , vise versa , give me tutorial phonegap learning.please can 1 me.
thanking in advance.
you need use cordova.exec api in able communicate between javascript code , android activity. maybe link can you.
first thing need declare custom plugin in config.xml
<feature name="customplugin"> <param name="android-package" value="com.androidapachecordovaplugin.customplugin" /> </feature>
implementing plug-in using java code
public class customplugin extends cordovaplugin { @override public boolean execute(string action, jsonarray args, callbackcontext callbackcontext) throws jsonexception { if (action.equals("sayhello")){ try { string responsetext = "hello world, " + args.getstring(0); callbackcontext.success(responsetext); } catch (jsonexception e){ callbackcontext.error("failed parse parameters"); } return true; } return false; } }
calling plug-in javascript
function initial(){ var name = $("#nameinput").val(); cordova.exec(sayhellosuccess, sayhellofailure, "customplugin", "sayhello", [name]); } function sayhellosuccess(data){ alert("ok: " + data); } function sayhellofailure(data){ alert("fail: " + data); }
Comments
Post a Comment