Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading url with pdf in monodroid webview

Im trying to load an url in a webview. The url links to a pdf file on the website. I want to display this pdf file in the webview. For some reason I only see a white screen and the pdf is not loading.

Here is 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;
            }
        }
    }
}
like image 556
Florian Schaal Avatar asked Oct 21 '22 11:10

Florian Schaal


1 Answers

I found a way that fits my appilication and still opens pdf's in de "webView" Here is the code:

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

This is not as smooth as in IOS webview but this way you will be able to open it regardless what device you have.

like image 65
Florian Schaal Avatar answered Oct 24 '22 05:10

Florian Schaal