Link to home
Start Free TrialLog in
Avatar of jomart mirza
jomart mirza

asked on

alert dialog from javascript not appear in xamarin crosswalk webview

how to show java-script alerts and HTML dialog input in Xamarin crosswalk ????
its working by default when using crosswalk in android studio ..
Avatar of Zakaria Acharki
Zakaria Acharki
Flag of Morocco image

Setting the WebChromeClient is needed to get the alert() , try set it like :

mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient());

Open in new window


Take a look at this discussion, It may be helpful in your case :

https://issuetracker.google.com/issues/36905249
Avatar of jomart mirza
jomart mirza

ASKER

yes this is for  built-in web view  but for crosswalk web view alert not working by default in Xamarin  like android studio i search google a lot didn't find anything it had to be some solution
Ok, I see, could you please share with as the relevant part of your code.
sure this is what i tried :

using Android.App;
using Android.Widget;
using Android.OS;
using System;
using Android.Views;
using Android.Content.Res;
using System.IO;

using Android.Util;
using Android.Content;
using System.Threading;
using System.Threading.Tasks;
using System.Text;
using System.Text.RegularExpressions;
using Org.Xwalk.Core;

namespace XWalk
{
    [Activity(Label = "XWalk", MainLauncher = true)]
    public class MainActivity : XWalkActivity
    {

        public static Activity fa;
        public Org.Xwalk.Core.XWalkView xwv;

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

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

        protected override void OnXWalkReady()
        {
            fa = this;

            var view = new RelativeLayout(this.BaseContext);
            var mp = ViewGroup.LayoutParams.MatchParent;
            xwv = new Org.Xwalk.Core.XWalkView(this.BaseContext, this);
            view.AddView(xwv);
            this.AddContentView(view, new ViewGroup.LayoutParams(mp, mp));
            XWalkPreferences.SetValue("enable-javascript", true);
            xwv.SetResourceClient(new XWalkResourceClient(xwv));\\ this code should work
            xwv.SetUIClient(new XWalkUIClient(xwv));\\or this
            xwv.LoadUrl("file:///android_asset/index.html");
   
        }
}
}

but its not working ..
Could you check if the JS is enabled using "getJavaScriptEnabled()" and make sure there's no message error logged.
JavaScript is enabled by default and i test it in other js function and its working  but the alert function and anything need dialog is not appears  so i even hired some one to find me an answer and i'm still waiting because i really supersized that i didn't find any easy solution for this issue
when i press  this HTML component it should give me dialog :

 <select>
            <option value="volvo">Volvo</option>
            <option value="saab">Saab</option>
            <option value="mercedes">Mercedes</option>
            <option value="audi">Audi</option>
        </select>


i get this in log output :

01-16 12:07:42.117 V/BoostFramework( 5609): BoostFramework() : mPerf = com.qualcomm.qti.Performance@48196b1
01-16 12:07:42.117 D/HwCust  ( 5609): Create obj success use class android.widget.HwCustTextViewImpl
01-16 12:07:42.127 D/HwCust  ( 5609): Create obj success use class android.widget.HwCustTextViewImpl
01-16 12:07:42.127 D/HwCust  ( 5609): Create obj success use class android.widget.HwCustTextViewImpl
01-16 12:07:42.137 D/HwCust  ( 5609): Create obj success use class android.widget.HwCustTextViewImpl
01-16 12:07:42.147 E/Dialog  ( 5609): show mWindowManager.addView RuntimeException
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.