I\'m trying to use monodroid with webkit to create an app. I am having a problem with letting the html page call a javascript method, which would be an interface to a method
I found that calling LoadData after AddJavascriptInterface was necessary. Also, with this change, assigning a WebChromeClient was not needed. For example, the modified version below runs fine:
public class Activity1 : Activity
{
const string html = @"
This is a paragraph.
";
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
WebView view = FindViewById (Resource.Id.web);
view.Settings.JavaScriptEnabled = true;
view.AddJavascriptInterface (new Foo (this), "Foo");
view.LoadData (html, "text/html", null);
}
class Foo : Java.Lang.Object, Java.Lang.IRunnable
{
Context context;
public Foo (Context context)
{
this.context = context;
}
public void Run ()
{
Toast.MakeText (context, "This is a Toast from C#!", ToastLength.Short).Show ();
}
}
}