在monodroid webview中使用pdf加载url
问题描述:
我试图在webview中加载一个url。该网址链接到网站上的pdf文件。我想在webview中显示这个pdf文件。出于某种原因,我只看到一个白色的屏幕,PDF不加载。在monodroid webview中使用pdf加载url
这里是代码:
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;
}
}
}
}
答
我找到了符合我的appilication仍然打开PDF在德“web视图”的方式下面是代码:
PodWebView.LoadUrl ("http://docs.google.com/viewer?url=" + PodUrl);
这不像在IOS webview中那样流畅,但是这样你就可以打开它,无论你有什么设备。
答
我不认为这是可能加载的WebView内的PDF文件。至少这是我通过阅读关于同一问题的其他SO问题而得到的印象。
我会亲自使用默认的PDF阅读器,而不是像这样:
var intent = new Intent(Intent.ActionView);
intent.SetDataAndType(uri, "application/pdf");
intent.SetFlags(ActivityFlags.ClearTop);
StartActivity(intent);
答
你必须把这个链接添加到您的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);
相同的代码和urlPDF之前添加这个环节是非常重要的“http://drive.google.com/viewerng/viewer?embedded=true&url=”