Download url using pdf in monodroid webview

I am trying to load a url in webview. The URL refers to the pdf file on the website. I want to display this pdf file in webview. For some reason, I only see a white screen and the PDF does not load.

Here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Webkit;

namespace TrackandTrace.Droid
{
    [Activity (Label = "PodActivity")]          
    public class PodActivity : Activity
    {
        public string PodUrl { get; set; }


        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.PodLayout);

            var PodWebView = FindViewById<WebView> (Resource.Id.webViewPod);
            PodUrl = Intent.GetStringExtra ("PodUrlString" ?? "No Pod Data available");

            PodWebView.Settings.AllowFileAccess = true;
            PodWebView.Settings.JavaScriptEnabled = true;
            PodWebView.Settings.BuiltInZoomControls = true;
            PodWebView.LoadData (PodUrl);

            PodWebView.SetWebViewClient (new PodWebViewClient ());

            // Create your application here
        }

        private class PodWebViewClient : WebViewClient
        {
            public override bool ShouldOverrideUrlLoading (WebView view, string url)
            {
                view.LoadUrl (url);
                return true;
            }
        }
    }
}
+5
source share
3 answers

I found a method that suits my appilication and still opens the PDF in "webView". Here is the code:

PodWebView.LoadUrl ("http://docs.google.com/viewer?url=" + PodUrl);

It is not as smooth as in the iOS web browser, but in this way you can open it no matter what device you have.

+2
source

I don’t think it’s possible to download PDF inside a WebView. At least this is the impression I get from reading other SO questions on the same issue.

PDF :

var intent = new Intent(Intent.ActionView);
intent.SetDataAndType(uri, "application/pdf");
intent.SetFlags(ActivityFlags.ClearTop);
StartActivity(intent);
+1

pdf-

WebView webview = FindViewById<WebView>(Resource.Id.webView1);
        urlPdf = ("example of url");
        WebSettings settings = webview.Settings;
        settings.JavaScriptEnabled = true;
        webview.LoadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + urlPdf);

and it’s important to add this link before urlPDF " http://drive.google.com/viewerng/viewer?embedded=true&url= "

0
source

All Articles