Android expansion file

半腔热情 提交于 2020-01-11 03:30:32

问题


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).

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)

I have implemented the following library :

"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.


回答1:


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);

**EDIT**

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");

**EDIT**

I think the location in which you placed your ZIP file is incorrect. According to Developer's Guide:

If your package name is com.example.android, you need to create the directory Android/obb/com.example.android/ on the shared storage space.

After successful testing, you can upload your Expansion ZIP along with your APK through Developer's Console.

Have you read through the APK Expansion Files? It's pretty straightforward.




回答2:


Even, if it is a zip file, it still needs to be stored in obb folder.



来源:https://stackoverflow.com/questions/14139587/android-expansion-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!