NoSuchMethod webview evaluatejavascript

1.7k Views Asked by At

I'm getting the error "no method with name = 'evaluateJavascript' in Landroid/webkit/Webiew" on Android 4.3

this is what i'm doing in my WebViewClient:

public override bool ShouldOverrideUrlLoading (WebView view, string url)
    {
        if(url.Contains ("addsResponseLoaded"))
        {
            view.EvaluateJavascript ("window.giveMeMyResponse();", controller.JSResultObj);
            //view.StopLoading ();
            return false;
        }
        return true;
    }

This happens only on older version of android and specific devices like the htc and galaxy. How can i get the return value of a javascript function android older versions than android kitkat?

2

There are 2 best solutions below

6
On

A simple look at developer page

public void evaluateJavascript (String script, ValueCallback<String> resultCallback)

Added in API level 19

Your minSdkVersion should be at least 19 for this method to work.

If you need to evaluate JavaScript on earlier versions of Android (3+), here is a little library:

https://github.com/evgenyneu/js-evaluator-for-android

0
On

Another alternative

webView.loadUrl("javascript:alert(injectedObject.toString())");