Android JellyBean JavascriptInterface annotation

Hey guys, Android JellyBeans introduces JavascriptInterface annotation, I don't see it in Xamarin.Android. How to do the same in Xamarin.Android?:

class JsObject {
@JavascriptInterface
public String toString() {
return "injectedObject";
}
}

webView.addJavascriptInterface(new JsObject(), "injectedObject");
webView.loadData("", "text/html", null);
webView.loadUrl("javascript:alert(injectedObject.toString())");

Best Answer

Answers

  • CheesebaronCheesebaron DKInsider, University mod

    Use [JavascriptInterface].

  • I need yet to import Mono.Android.Export.dll? Thanks a lot.

  • CheesebaronCheesebaron DKInsider, University mod

    I did some JavascriptInterfacing a while back, where I had to make a dummy .java file with the methods and signatures needed for the interfaces and used JNI to make a wrapper for C#. You can look in https://github.com/Cheesebaron/MonoDroid.WAToolkit/tree/master/MonoDroid.WAToolkit.Library/Login for a sample.

  • Thanks a lot, guys :D:D:D:D

Sign In or Register to comment.