Making calls to webpage via javascript interface stopped working after updating Android System webview to v- 92.0.4515.105. This issue is mostly on Samsung devices, running Android 11. Works perfectly fine on other devices.
This is my settings:
// attach the interface
webView.addJavascriptInterface(this, "Android");
//setup webview settings
private void setupWebViewClients() {
this.webView.getSettings().setJavaScriptEnabled(true);
this.webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
this.webView.getSettings().setDomStorageEnabled(true);
if (Build.VERSION.SDK_INT >= 19) {
this.webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
this.webView.getSettings().setAppCacheEnabled(true);
}
else {
this.webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
this.webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
//App logic
});
this.webView.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//App logic
}
public void onPageFinished(WebView view, String url) {
//App logic
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
}
});
}
And I am calling functions this way:
this.webView.loadUrl("javascript:updateGps('dumny',dummy')";
Is there any other settings introduced in Android 11 that I am not aware of? Or it's the bug in Google's Android system webview? Please help me out if there's any work around. Thank you.