[mono-android] WebView Javascript Interface and exposing methods through JNI
Jonathan Pryor
jonp at xamarin.com
Thu Jan 5 13:52:45 EST 2012
On Jan 5, 2012, at 4:50 AM, Tomasz Cielecki wrote:
> I am trying to add a javascript interface to my webview but it the method in the object I pass to the webview does not get triggered.
...
> I was thinking whether it is possible to tell mandroid to put the methods in the generated Java files, so that Java knows of them.
Yes, though as you saw it breaks because the Android Callable Wrapper use @Override, which breaks you.
The solution [0] is a level of indirection: declare a Java-side interface, then bind that interface in C# and implement it. You'll still need to write some Java code, but only the interface declaration.
Unfortunately, binding interfaces is more complicated. Fortunately, I have a sample:
https://github.com/xamarin/monodroid-samples/blob/master/SanityTests/Adder.java
https://github.com/xamarin/monodroid-samples/blob/master/SanityTests/ManagedAdder.cs
I also have docs, but those are awaiting review.
- Jon
[0] Yes, this isn't a very good solution. We'll be working on improving this in future releases.
More information about the Monodroid
mailing list