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
// C#
// !!!
using Java.Interop; // add link to Mono.Android.Export
public class Activity1 : Activity
{
const string html = @"
This is a paragraph.
";
class Foo : Java.Lang.Object // do not need Java.Lang.IRunnable
{
Context context;
public Foo (Context context)
{
this.context = context;
}
[Export] // !!! do not work without Export
[JavascriptInterface] // This is also needed in API 17+
public string SomeMethod(string param)
{
Toast.MakeText (context, "This is a Toast from C#!" + param, ToastLength.Short).Show ();
}
}
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);
}
}