gpt4 book ai didi

java - 我的设备中的 Pdf 文件无法在 WebView 中加载

转载 作者:行者123 更新时间:2023-12-01 17:20:31 30 4
gpt4 key购买 nike

我正在尝试通过 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

我错过了什么?

最佳答案

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

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

那又如何图书馆

这个网站上有很多像这样的答案 here推荐这个库来读取本地pdf文件:

AndroidPdfViewer

关于java - 我的设备中的 Pdf 文件无法在 WebView 中加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61301369/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com