添加接口中的None个方法已经用@android.webkit.JavascriptInterface注解;它们将不会在 API 17 中显示

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

我正在使用 webview 并想加载一个 JScode 以在该 webview 中显示。但是我遇到了一个问题 API16.It 永远不会加载 JS 页面。它给我一个错误:

这是我的代码:

        @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());
        }

在阅读不同站点的解决方案后,我开始知道添加注释。但是写完注解,还是报错

任何人都可以检查并帮助我回复

谢谢

您必须将 @JavascriptInterface 添加到 Wscript class 的 public 方法中。

如果您的代码被proguard遮挡,您还应该将-keepattributes *Annotation*添加到proguard的配置文件中。

您必须添加

@SuppressLint("JavascriptInterface")

到您使用 webView 对象的 public 方法。