Issue with WebView.EvaluateJavaScript in Android Xamarin -


i using following code injecting java script in android web view

webview

webview = findviewbyid<webview> (resource.id.learningwebview); if (null != webview) {     webview.settings.javascriptenabled = true;     webview.settings.setsupportzoom (true);     webview.setwebviewclient (new customwebviewclient ());   } 

webview client implementation

public class customwebviewclient : webviewclient {     public override bool shouldoverrideurlloading (webview view, string url)     {         view.loadurl (url);         return true;     }      public override void onpagestarted (webview view, string url, android.graphics.bitmap favicon)     {      }      public override void onpagefinished (webview view, string url)     {         base.onpagefinished (view, url);         hidelearningdivs (view);     }       void hidelearningdivs (webview view)     {         try {              view.evaluatejavascript ("document.getelementbyid(\"suitebar\").parentnode.style.display='none'", new javascriptresult ());         } catch (exception ex) {             console.writeline (ex.message);         }      } 

ivaluecallback implementation

public class javascriptresult :  ivaluecallback {     public intptr handle {         get;         set;     }      public void dispose ()     {      }        public void onreceivevalue (java.lang.object result)     {      } } 

but during time of executing application getting following error.

java.lang.nosuchmethoderror: no method name='evaluatejavascript' signature='(ljava/lang/string;landroid/webkit/valuecallback;)v' in class landroid/webkit/webview;

can please me find wrong implementation.

i link found answer below, need check android kitkat (4.4), since function not introduced until then. if device running lower 4.4, may need different value if need it. such using hybrid webview of kind (check out xamarin forms labs version of perhaps) and/or using addjavascriptinterface()

here code:

if(android.os.build.version.sdkint >= android.os.buildversioncodes.kitkat) {     webview.evaluatejavascript("javascript:goback();", null); } else {     webview.loadurl("javascript:goback();"); } 

https://forums.xamarin.com/discussion/24894/webview-evaluatejavascript-issues

*edit: since writing this, found excellent post adam pedley (who apparently have been linking lot lately) covers doing xamarin forms mentions change in android 4.2 js engine. running javascript might work first time sets document object script result, may need assign result of document.getelementbyid() variable in order work around this: var x = document.getelementbyid().


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -