包括在一个应用程序的PDF文件的最佳方法应用程序、文件、方法、PDF

2023-09-13 23:59:30 作者:我善变偏执烂脾气.

我要开发一个应用程序,它基本上是一个PDF阅读器:它是由一个列表组成,每个列表元素是一个PDF文件的名称,当用户点击列表元素的PDF弹出出来,读取PDF阅读器安装在设备上。

I have to develop an app which is basically a pdf reader: it is composed by a list, each list element is a pdf file name, when user clicks on a list element the pdf is popped out, read by a pdf reader installed on the device.

现在,问题是,我想包括这些PDF文件在我的应用程序。 到目前为止,我发现的唯一方法是将它们设置为资源,但问题是,每次我要显示其中一人我就必须将它复制的公共文件夹,这显然需要时间......不有另一种方式?

Now, problem is that i'd like to include these pdfs in my app. Till now the only way I found is to set them as resource, but the problem is that each time I want to display one of them I'll have to copy it in a public folder and this obviously takes time...isn't there another way?

推荐答案

您可以添加的ContentProvider 您的应用程序,流的PDF文件,从资源的其他进程。例如,我的 StreamProvider 扩展Android的 FileProvider 来添加对从原料资源或资产提供文件服务的支持。演示项目,特别是展示了从服务资产PDF。

You can add a ContentProvider to your app that streams the PDFs to the other process from the resource. For example, my StreamProvider extends Android's FileProvider to add support for serving files from raw resources or assets. The demo project, in particular, demonstrates serving a PDF from assets.