简体   繁体   中英

How do I handle results from Control.EvaluateJavascript in xamarin?

I know how to call js-functions with the Android.Webkit as long as I dont have to handle a return-value:

 Control.EvaluateJavascript("removeAllPins()", null);

But I dont know how to call a function that returns a function? The function takes an object of IValueCallback as a paramter but I can't create an instance of it because it's an interface and not a class.
How do I get the result of a js-function thats called in Android with EvaluateJavascript?

You could do in your webview renderer like below,refer to this :

Control.EvaluateJavascript("javascript: removeAllPins();", new EvaluateBack());

class EvaluateBack : Java.Lang.Object,IValueCallback
  {

      public void OnReceiveValue(Object value)
      {

        Toast.MakeText(Android.App.Application.Context, value.ToString(), ToastLength.Short).Show();// you will get the value you want to return.
      }
   }

maybe:

Control.EvaluateJavascript("removeAllPins()", null, new gitGud());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM