安卓扩展文件 [英] Android expansion file
问题描述
我正在尝试制作一个包含约 80 个月 PNG 格式的应用程序(这是一个离线应用程序,因此我必须将它们存储在手机上).
I am trying to do an application which contain ~80mo of PNG (It's an offline app so I have to store them on the phone).
该应用程序在本地运行良好,但我无法上传超过 50 个月的 apk.所以我试图实现一个包含我所有 PNG 的扩展文件.所以我在 Linux 上使用这个简单的命令: _zip_ -0 _main.1.com.ctai.irisst.zip_ *_.png_
在我的/res/drawable-mdpi 上创建我的扩展文件,然后把手动到/Android/data/com.ctai.irisst/
然后,我使用此代码解压我所有的数据都在手机的存储中,但是当我启动应用程序时,我只得到一个黑屏大约 10 秒,然后 Android 告诉我应用程序没有响应.我可以在文件浏览器中看到大约 10 个 PNG 图像被解压缩,并且在 Logcat
中每秒提取 1 个文件.(如果我使用缓冲区,加载我的应用程序仍然需要 20 秒以上)
The application works perfectly in local but I can't upload an apk > 50mo. So I am trying to implement an expansion file which will contain all my PNGs. So I use this simple command on Linux: _zip_ -0 _main.1.com.ctai.irisst.zip_ *_.png_
on my /res/drawable-mdpi to create my expansion file and then put it manually to /Android/data/com.ctai.irisst/
Then, I use this code to unzip all my data on the storage of the phone, but when I start the app, I only get a blank screen for like 10s, and then Android tells me that the application is not responsive. I can see in a file explorer that ~10 PNG images are unzipped and in the Logcat
that 1 file is extracted every second. (and if I use a buffer, it still take >20s to load my application)
我已经实现了以下库:
"downloader_library","licencing_library","Sample_downloader" and "zip_file"
但我暂时没有真正使用它.(我应该吗?怎么做?)
but I didn't really used it for the moment. (should I ? How ?)
我的问题很简单,如何在不干扰用户体验的情况下简单地创建扩展文件并使用我的图像?没有找到那么多关于扩展文件的教程,也没有示例项目,所以有点迷茫.
My question is simple, how can I simply create an expansion file and use my images without interfering with the user experience ? I have not found so many tutorials on Expansion Files, and no sample projects, so I'm a bit lost.
推荐答案
您无需解压缩包.您可以使用以下命令读取扩展 ZIP 文件中的所有 PNG:
You don't need to unzip your package. You can read all your PNGs within Expansion ZIP file with this:
// Get a ZipResourceFile representing a merger of both the main and patch files
ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(appContext,
mainVersion, patchVersion);
// Get an input stream for a known file inside the expansion file ZIPs
InputStream fileStream = expansionFile.getInputStream(pathToFileInsideZip);
**编辑**
请注意,在上面的代码中,InputStream 将指向 ZIP 存档中的文件,而不是 ZIP 文件本身.例如,如果您将 flower.png 放在 ZIP 存档中名为 background 的目录下,则可以按如下方式为该文件设置 InputStream:
Notice that in the code above, InputStream will point to the file inside your ZIP archive and not the ZIP file itself. For example, if you placed flower.png under a directory called background inside your ZIP archive, you can have an InputStream to that file as follows:
InputStream fileStream = expansionFile.getInputStream("background/flower.png");
**编辑**
我认为您放置 ZIP 文件的位置不正确.根据开发者指南:
I think the location in which you placed your ZIP file is incorrect. According to Developer's Guide:
如果你的包名是com.example.android,你需要创建共享存储上的目录 Android/obb/com.example.android/空间.
If your package name is com.example.android, you need to create the directory Android/obb/com.example.android/ on the shared storage space.
测试成功后,您可以通过开发者控制台上传扩展包 ZIP 和 APK.
After successful testing, you can upload your Expansion ZIP along with your APK through Developer's Console.
您是否已阅读APK 扩展文件?非常简单.
Have you read through the APK Expansion Files? It's pretty straightforward.
这篇关于安卓扩展文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!