简体   繁体   中英

None of the methods in the added interface have been annotated with @android.webkit.JavascriptInterface; they will not be visible in API 17

I am using a webview and want to load a JScode to show in that webview. However I am getting a problem above API16.It never loads the JS page. It gives me an error:

Here is my code:

        @JavascriptInterface

    public void loadWebviewUrl(){
            Map <String, String> extraEncryptionHeaders = new HashMap<String, String>();
            extraEncryptionHeaders.put("X-APP-DEVICETYPE", "ANDROID"); 
            appVersionname=CommonMethods.getAppVersion(WebPayUActivity.this);
            extraEncryptionHeaders.put("X-APP-APPVERSIONNAME", appVersionname); 
            extraEncryptionHeaders.put("X-DEVICE", Constant.ANDROIDID); 
            extraEncryptionHeaders.put(Constant.HEADER_SECURITY_KEY, Constant.SECURITY_HASH_VALUE);
            mWebView.loadUrl(mPayUrl, extraEncryptionHeaders);

**//getting error in this line that has been mentioned above**
            mWebView.addJavascriptInterface(new Wscript(WebPayUActivity.this),
                    "Android");
            screenDpi=CommonMethods.getResoltuion(this);
            mWebView.setWebViewClient(new MyWebViewClient(this));

            mImageView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    customAlertDialog();    
                }
            });
            mWebView.setWebChromeClient(new WebChromeClient());
        }

After reading the solutions at different sites I got to know to add annotation. But after writing the annotation, the error is still the same.

Can anyone please check and help me back

Thanks

You must add

@SuppressLint("JavascriptInterface")

to the your public methods which you used your webView object.

You must add @JavascriptInterface to the public methods of your Wscript class.

If your code is obscured with proguard , you should also add -keepattributes *Annotation* to the configuration file of proguard .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM