appView.addJavascriptInterface() does not work on API 17

i am able to use java function from my phonegap java script function and android 2.2
but same code is not run on API 17. what should i have to do to call native java code on from java script in API 17.

i use this code in my java file

  • Android sdk download/update failing
  • 'name' attribute should be defined - error in android manifest
  • Popup DatePicker for EditText
  • Android Virtual Device(AVD) creation issue on Ubuntu 16.04
  • How to completly kill/remove/delete/stop an AsyncTask in Android
  • how to finish all activities and close the application in android?
  •  objCustomNativeAccess = new CustomNativeAccess(this, appView);

    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;
             * Get the 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 my java script i use this line to call this login function

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

    so using this i successfully call this on api 2.2 but when i run this code on api 17 it give me error

    Uncaught TypeError: Object [object Object] has no method ‘login’ at file:///android_asset/www/index.html:81

    how i can i use this on api 17

    Related posts:

    Intent URI to launch Gmail App
    Get External SDCard Location in Android
    iPhone or Android apps that use SMS based authentication?
    How can I find and run the keytool
    How to replace the activity's fragment from the fragment itself?
    How to get the Correct orientation of the image selected from the Default Image gallery
  • Download apk file from S3 using DownloadManager
  • FragmentTransaction .attach and .detach for Actionbar tabs
  • PreferenceActivity: save value as integer
  • Uncheck all RadioButton in a RadioButtonGroup
  • Recover file in Android Studio?
  • Google map showing additional copyright text on some devices
  • 4 Solutions collect form web for “appView.addJavascriptInterface() does not work on API 17”

    What you have to do on API 17 is annotate your method with @JavascriptInterface:

    Public class CustomNativeAccess {

    and then get rid of the constructor part:

    /*private WebView mAppView;
        private DroidGap mGap;
        public CustomNativeAccess(DroidGap gap, WebView view) {
            mAppView = view;
            mGap = gap;

    Also be sure you import JavascriptInterface in your project:

     import android.webkit.JavascriptInterface;

    You can read about it more here:,%20java.lang.String%29

    Edit: You will have to annotate each method with @JavascriptInterface within your class that you’d like to access from Javascript.

    From the Android 4.2 documentation:

    Caution: If you’ve set your targetSdkVersion to 17 or higher, you must
    add the @JavascriptInterface annotation to any method that you want
    available your web page code (the method must also be public). If you
    do not provide the annotation, then the method will not accessible by
    your web page when running on Android 4.2 or higher.

    Source: Android WebView Doc (emphasis added)

    I just wrote the web application with addJavascriptInterface with API 17, it works well. I don’t know what happened to your code. Maybe you can try these:

    make sure you add the :

    WebSettings webSettings = appView.getSettings();

    Second, why do you use super.loadUrl, not appView to load the html?

    objCustomNativeAccess = new CustomNativeAccess(this, appView);
    appView.addJavascriptInterface(objCustomNativeAccess, "CustomNativeAccess");


    1. Lower the android:targetSdkVersion in the manifest file to 16.
    2. Change the compilation api level to 17 in target=android-17 and annotate the callback method with @JavascriptInterface.
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.