Android webview with parameters not working as expected

206 Views Asked by At

I am calling the javascript function from the android app with two parameters. first one is the boolean and the second one is a string value. But it's not behaving as expected. Please let me know if anything wrong with my implementation

mWebview.evaluateJavascript("OnHistory(" + true + ",'" + unitNumber +"')", new ValueCallback<String>() {
                                @Override
                                public void onReceiveValue(String value3) {
                                   
                                }
                            });
2

There are 2 best solutions below

1
Chan Lung On

"javascript:OnHistory(" + true + ",'" + unitNumber +"')"

Please try this command, then if you are using webview.stopLoading() function, then remove it. it's removing javascript libraries in chrome version 92.

Hope it helpsful for you.

0
Jakub Pruszyński On

Before usage of javascript you have to enable it.

val myWebView: WebView = findViewById(R.id.webview)
myWebView.settings.javaScriptEnabled = true

Cheers