java - appView.addJavascriptInterface() does not work on API 17 -


i able use java function phonegap java script function , android 2.2 same code not run on api 17. should have call native java code on java script in api 17.

i use code in java file

 objcustomnativeaccess = new customnativeaccess(this, appview);             appview.addjavascriptinterface(objcustomnativeaccess,                     "customnativeaccess");     super.loadurl("file:///android_asset/www/index.html"); 

my customnativeaccess class is

public class customnativeaccess {         private webview mappview;         private droidgap mgap;          /**          * constructor          *           * @param gap          * @param view          */         public customnativeaccess(droidgap gap, webview view) {             mappview = view;             mgap = gap;         }          /**          * device phone number          *           * @return          */         public jsonobject login(string email, string password) {             jsonobject object = new jsonobject();                     object.put("login_status", login_status);             object.put("date", datestring);             return object;         } 

and in java script use line call login function

 var value = window.customnativeaccess.login(email,pass); 

so using call on api 2.2 when run code on api 17 give me error

uncaught typeerror: object [object object] has no method 'login' @ file:///android_asset/www/index.html:81

how can use on api 17

what have on api 17 annotate method @javascriptinterface:

public class customnativeaccess {    @javascriptinterface 

and rid of constructor part:

/*private webview mappview;     private droidgap mgap;     public customnativeaccess(droidgap gap, webview view) {         mappview = view;         mgap = gap;     } */ 

also sure import javascriptinterface in project:

 import android.webkit.javascriptinterface; 

you can read more here: http://developer.android.com/reference/android/webkit/webview.html#addjavascriptinterface%28java.lang.object,%20java.lang.string%29

edit: have annotate each method @javascriptinterface within class you'd access javascript.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -