1

I need to manipulate the links in the html so i'm using a WebViewClient to do it. The problem is I've got some iframes that load local html pages and they aren't displyed. But, if i use the WebChromeClient they works!

So, i want to use the both of them but it doesn't work. It seems that only the webViewClient works, I don't know why.

I set Internet permission and write to external storage (because my html is located in the storage) in the manifest and enabled the hardware acceleration as well.

this is my code:

public class BChromeClient : WebChromeClient
    {
        public BChromeClient ()
        {}

        public bool OnShowCustomView(WebView view, string url)
        {
            return true;
        }

        public void OnHideCustomView()
        {
        }


    }

    public class BWebClient : WebViewClient
    {
        int _position;
        string _path;
        Activity _parent;
        ViewPager _pager;
        string _chapName;
        public BWebClient (int position, string Path, Activity Parent, ViewPager Pager, string ChapName){
            _position = position;
            _parent = Parent;
            _path = Path;
            _pager = Pager;
            _chapName = ChapName;
        }

        public override void OnPageFinished (WebView view, string url)
        {
            base.OnPageFinished (view, url);
            view.ScrollTo (0, _position);
        }

        public override bool ShouldOverrideUrlLoading (WebView view, string url)
        {

            if (url.StartsWith ("navigate")) {
                string destination = url.Substring (url.IndexOf ("navigate://") + "navigate://".Length);
                int DestinationChapter = Int32.Parse (destination.Substring (0, destination.IndexOf("_")));
                int l = destination.IndexOf("_") + 1;
                int b = destination.Length - l;
                int DestinationPage = Int32.Parse (destination.Substring (l,b));



                if (DestinationPage == 0) {
                    _pager.SetCurrentItem(DestinationChapter ,true);
                    WebView _web = (WebView)_pager.FindViewWithTag(300 + DestinationChapter);
                    _web.LoadUrl ("file://" + _path + "/" + _chapName);
                }



            } else if (url.StartsWith ("pdf")) {
                string file_path = _path + url.Substring (5);
                if (System.IO.File.Exists(file_path)) {
                    Android.Net.Uri pdfFile = Android.Net.Uri.FromFile (new Java.IO.File (file_path));
                    Intent pdfIntent = new Intent (Intent.ActionView);
                    pdfIntent.SetDataAndType (pdfFile, "application/pdf");
                    pdfIntent.SetFlags (ActivityFlags.NoHistory);
                    _parent.StartActivity (pdfIntent);
                }
            }

            return true;
        }
    }

While in the fragment OnCreateView method (Yeah, i'm using a webview inside a PageViewer, but i don't think it is important to know).

web_view = view.FindViewById<WebView> (Resource.Id.webview);
        web_view.SetWebChromeClient (new BChromeClient ());
        web_view.SetWebViewClient(new BWebClient(_position,_path,_parent, _pager, _chap.Name ));
        web_view.SetBackgroundColor(Color.Transparent);
        web_view.Settings.JavaScriptEnabled = true;
        web_view.Settings.AllowFileAccess = true;
        //web_view.Settings.SetPluginState (WebSettings.PluginState.On);
BlackShawarna
  • 247
  • 8
  • 23

1 Answers1

0

In MainActivity.cs

web_view..webviewClient = new ExtendedWebViewClient();
 web_view.SetWebChromeClient(new ExtendedChromeClient(MainActivity));
            web_view.SetWebViewClient(this.webviewClient);