我正在尝试通过以下网址在 Android WebView 中打开 pdf 文件:
http://bijsluiters.fagg-afmps.be/registrationSearchServlet?key=BE-TU441865&leafletType=leafletNL
当我在线搜索有关如何实现此目标的信息时,我发现 您需要在其前面扩展 url:“http://docs.google.com/gview?embedded=true&url= ”
但是当我这样做时,我只能看到 html,就像在浏览器中打开链接时一样: “https://docs.google.com/gview?embedded=true&url=http://bijsluiters.fagg-afmps.be/registrationSearchServlet?key=BE-TU441865&leafletType=leafletNL”
如何在我的 webview 中查看实际的非 html 内容?
public class BijsluiterFragment : Android.Support.V4.App.Fragment
{
//Title = DomainController.Instance.GetWord("BijsluiterTitle");
private View view;
private WebView webview;
private string url;
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
view = inflater.Inflate (Resource.Layout.BijsluiterFragment, container, false);
webview = view.FindViewById<WebView> (Resource.Id.webView);
webview.Settings.JavaScriptEnabled=true;
webview.Settings.SetPluginState (WebSettings.PluginState.On);
if(!String.IsNullOrEmpty(url))
{
webview.LoadUrl ("http://docs.google.com/gview?embedded=true&url="+url);
}
return view;
}
public void SetUrl(string url)
{
this.url = url;
}
}
我也尝试过“loadwithbaseurl”方法,但它也不起作用......
最佳答案
我用这个解决了同样的问题:
if (url.endsWith(".pdf")) {
try {
String urlEncoded = URLEncoder.encode(url, "UTF-8");
url = "http://docs.google.com/viewer?url=" + urlEncoded;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
使用此前缀:“http://docs.google.com/viewer?url= ”,WebView 使用 GoogleDocs 打开 pdf。
希望对你有帮助!!
关于android - 从 url 在 Android Webview 中查看 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28547649/