我设备中的 Pdf 文件未在 WebView 中加载

Pdf file from my device does not load in WebView

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

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

我错过了什么?

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

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

那什么图书馆

这个网站上有很多答案,比如这个 推荐这个图书馆阅读本地 pdf 文件:

AndroidPdfViewer