Uniform JavaScript

Monodroid does not yet support JavaScript in the WebView interface.

I am looking for an example .java file that can be used with this workaround.

IntPtr JavaScriptInterface_Class = JNIEnv.FindClass ("the/package/for/JavaScriptInterface"); 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"); 
+4
source share
2 answers

You can use custom .java , for example:

 // TODO: use an actually valid package name. :-) package the.package.for; public class JavaScriptInterface { // The JNI in the original question uses a default constructor. // Either provide one explicitly or use the implicit one... public JavaScriptInterface () { } // TODO: add any methods you want invokable from JavaScript here. } 

Remember to set the Build action for your .java file on AndroidJavaSource .

+2
source

I know this thread is already a little old. But I found this when I was looking for the same thing, and here is a solution how you can use C # methods

 public class AndroidInterface : Java.Lang.Object { [Export] public void Save(string text) { } } AndroidInterface androidInterace = new AndroidInterface(); webView.AddJavascriptInterface(androidInterface, "Android"); 
+1
source

All Articles