Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 464
Gaurav Arora Avatar asked Feb 03 '15 07:02

Gaurav Arora


1 Answers

You must add

@SuppressLint("JavascriptInterface")

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

like image 117
Cüneyt Avatar answered Nov 14 '22 02:11

Cüneyt