【问题标题】:Pdf file from my device does not load in WebView我设备中的 Pdf 文件未在 WebView 中加载
【发布时间】:2020-04-19 08:13:38
【问题描述】:

我正在尝试通过 WebView 加载 PDF 文件。我在 StackOverflow 中尝试了几乎所有的答案,但仍然失败。这是我的结果代码:

WebView webView = findViewById(R.id.webView);
WebSettings settings = webView.getSettings();
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setBuiltInZoomControls(true);
webView.setContentDescription("application/pdf");
webView.loadUrl("file:///data/user/0/com.example.pdfwebviewer/files/masterlist.pdf");

我从几个来源获得了这段代码:

  1. How to open local PDF file in WebView in Android?
  2. Can't open a local PDF in webview using file://
  3. Open PDF in a WebView

我错过了什么?

【问题讨论】:

标签: java android webview


【解决方案1】:

看来你必须尝试使用​​一些库,因为 android-WebView 似乎不支持.pdf 文件。

  1. Mentioned here
  2. Mentioned here in a comment to the main question

那么图书馆呢

这个网站上有很多答案,比如here 推荐这个库来阅读本地 pdf 文件:

AndroidPdfViewer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 2020-02-02
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多