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.

http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v610/06_05_android_-_adding_native_functionality_to_hybrid_application_with_apache_cordova_plugin.pdf

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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -