appView.addJavascriptInterface() does not work on API 17

前端 未结 4 2125
我寻月下人不归
我寻月下人不归 2021-02-01 05:27

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 fr

4条回答
  •  别跟我提以往
    2021-02-01 06:27

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

    public class CustomNativeAccess {
       @JavascriptInterface
    

    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: WebView Android

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

提交回复
热议问题