Hi,

I tried the JS interface in Java and it works fine, but I tried to replicate
the code in Mono for Android and it does not work. What am I doing wrong?

    public class Activity1 : Activity
    {
        WebView appView;

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            // Reference to the WebView
            appView = FindViewById<WebView>(Resource.Id.appView);

            // Enable JavaScript
            WebSettings settings = appView.Settings;
            settings.JavaScriptEnabled = true;
   
            // Set the HTML data
            appView.AddJavascriptInterface(new JavaScriptInterface(this),
"Android");
            string texto = "<input type=\"button\" value=\"Say hello\"
onClick=\"showAndroidToast('Hello Android!')\" /> " +
                           " " ;
            appView.LoadData(texto, "text/html" , "utf-8");
        }
    }
    
    public class JavaScriptInterface : Java.Lang.Object
    {
        Context _context;

        /** Instantiate the interface and set the context */
        public JavaScriptInterface (Context c)
        {
            _context = c;
        }

        /** Show a toast from the web page */
        public void showToast (string toast)
        {
            Toast.MakeText(_context, toast, ToastLength.Short).Show();
        }
    }    

Thanks.

Marcio Alexandroni.

--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/JavaScript-Interface-tp4693178p4693178.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to