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;
}
}
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With