Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using WebView Evaluate Script Xamarin

I have an html page loaded in Android WebView.

I am attempting to execute a java script function using the MotionEvenAction.Down event.

Here is the code that's not working

 webView.Touch += (s, e) =>
        {
            if (e.Event.Action == MotionEventActions.Down)
            {
                webView.EvaluateJavascript(((string.Format("poweSelected({0})", 3), new JavascriptResult() ));

            }

        };


 public class JavascriptResult : Java.Lang.Object, Android.Webkit.IValueCallback
{
    public string Result;
    public void OnReceiveValue(Java.Lang.Object result)
    {
        string json = ((Java.Lang.String)result).ToString();
        Result = json;

    }
}

I am getting the error message -- (EvaluateJavascript has red line under it)

There is no argument given that corresponds to the required formal parameter 'resultCallback' of 'WebView.EvaluateJavascript(string, IValueCallback)'

As far as I knwo i am implemetnting the ivaluecallback interface correctly and I have found examples exactly like the that seem to be working.

Any help would be appreciated Mark

like image 214
Mark Avatar asked Dec 11 '25 18:12

Mark


1 Answers

Like @Sushi has mentioned:

Replace this:

 webView.EvaluateJavascript(((string.Format("poweSelected({0})", 3), new JavascriptResult() ));

with:

webView.EvaluateJavascript(string.Format("poweSelected({0})", 3), new JavascriptResult());
like image 88
Robbit Avatar answered Dec 14 '25 07:12

Robbit