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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With