Using WebView.AddJavascriptInterface With MonoDroid
I'm using MonoDroid, and would like to make C# code callable from my WebView. I'm doing this (C#): protected override void OnCreate(Bundle bundle) { [...] LinearLay
Solution 1:
A) Add the [Export] attribute on your method.
B) On xamarian website: http://docs.xamarin.com/android/recipes/Controls/WebView/Call_C%23_from_JavaScript
C) write your JavaScriptInterface type in a .java file, include the .java file in your project with a AndroidJavaSource Build action, and in Activity1.OnCreate(), do:
IntPtr JavaScriptInterface_Class = JNIEnv.FindClass ("the/package/for/JavaScriptInterface");
// TODO: Update "the/package/for" as appropriate for your type.
IntPtr JavaScriptInterface_ctor = JNIEnv.GetMethodID (JavaScriptInterface_Class, "<init>", "()V");
IntPtr instance = JNIEnv.NewObject (JavaScriptInterface_Class, JavaScriptInterface_ctor);
appView.AddJavascriptInterface (new Java.Lang.Object (instance), "Android");
Solution 2:
You might want to look at the Java bridge code that gets generated for your JSAccesibleObject class. Look in \obj\Debug\android\src and see what kind of methods/properties are in there. These should be the methods that would be callable from Java.
Post a Comment for "Using WebView.AddJavascriptInterface With MonoDroid"