且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何打开存储无论是在资源/原材料或资产文件夹中的PDF文件?

更新时间:2023-09-28 09:32:28

您将能够从显示它生/ 资产/ 如果您的应用程序实际上实现了一个PDF阅读器。既然你想让它显示在一个单独的应用程序(如Adobe Reader的),我建议做如下:

You would be able to show it from raw/ or assets/ if your application actually implemented a PDF reader. Since you want it to be displayed in a separate application (such as Adobe Reader), I suggest doing the following:

  1. 保存在资产/ 目录中的PDF文件。
  2. 当用户想查看某个地方将它复制公开。看看openFileOutput$c$c>或getExternalFilesDir$c$c>.
  3. 启动意图就像你现在正在做,除非使用getAbsolutePath()$c$c>上为意图的数据新创建的文件。
  1. Store the PDF file in the assets/ directory.
  2. When the user wants to view it, copy it somewhere public. Look into openFileOutput or getExternalFilesDir.
  3. Launch the Intent just like you are doing now, except use getAbsolutePath() on the newly created file for the intent's data.

请注意,用户可能没有一个PDF阅读应用程序。在这种情况下,捕捉是有用的ActivityNotFoundException$c$c>并显示相应的消息。

Be aware that a user might not have a PDF reading application. In this case, it is useful to catch the ActivityNotFoundException and show an appropriate message.