简体   繁体   English

如何使用MuPDF从android资产文件夹中读取文件?

[英]How to read file from asset folder in android with MuPDF?

I am building an app for viewing pdf file. 我正在构建一个用于查看pdf文件的应用程序。 I could build MuPDF library. 我可以建立MuPDF库。

I want my app to open only pdf files which I will keep in /assets folder. 我希望我的应用程序只打开pdf文件,我将保留在/ assets文件夹中。 Source code supplied comes with code which reads file from SD card. 提供的源代码附带从SD卡读取文件的代码。 I want to read and display files supplied with app (either in /assets or /raw folder whichever is viable) 我想阅读并显示app附带的文件(在/ assets/ raw文件夹中哪个是可行的)

I am new to NDK. 我是NDK的新手。 Please guide me. 请指导我。

The files in assets are not stored as individual files on the device. 资产中的文件不会作为单个文件存储在设备上。 The APK is a compressed ZIP file; APK是压缩的ZIP文件; the assets folder only exists there. assets文件夹只存在于那里。

Copy the file from assets on the apps' first run (see eg here for an example). 在应用程序首次运行时从资产中复制文件(例如,请参见此处 )。

EDIT: If the only way MuPDF takes files is by file name, you're out of luck. 编辑:如果MuPDF采取文件的唯一方式是文件名,你运气不好。 It doesn't have to be SD card - you can use your app's internal storage folder (use Context.getDir() to get one). 它不一定是SD卡 - 您可以使用应用程序的内部存储文件夹(使用Context.getDir()获取一个)。 If it can take an in-memory data block, you can read the file on the caller side by means of AAssetManager (or in Java) and pass the data to the library. 如果它可以占用内存数据块,您可以通过AAssetManager (或Java)在调用方面读取文件,并将数据传递给库。

Maybe Android has an in-memory temp filesystem that you could leverage; 也许Android有一个你可以利用的内存临时文件系统; I'm not sure. 我不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM