Android extension file

I am trying to make an application that contains ~ 80mo PNG (this is a standalone application, so I have to store them on my phone).

The application works fine in local mode, but I can not download apk> 50mo. Therefore, I am trying to implement an extension file that will contain all my PNGs. So I use this simple command in Linux: _zip_ -0 _main.1.com.ctai.irisst.zip_ *_.png_ on my / res / drawable-mdpi to create an extension file and then manually put it in /Android/data/com.ctai.irisst/
Then I use this code to unpack all my data on the phone’s memory, but when I launch the application, I get a blank screen, for example, 10 seconds, and then Android tells me that the application does not respond. In the file explorer, I see that ~ 10 PNG images are unpacked, and in Logcat 1 the file is extracted every second. (and if I use a buffer, it will still take me> 20 seconds to load my application)

I implemented the following library:

 "downloader_library","licencing_library","Sample_downloader" and "zip_file" 

but I actually haven't used it at the moment. (should i? how?)

My question is simple, how can I just create an extension file and use my images without interfering with the user? I did not find so many extension file tutorials and no sample projects, so I lost a bit.

+4
source share
3 answers

You do not need to unzip your package. You can read all of your PNGs in the Expansion extension 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 **

Please note that in the above code, the InputStream will point to the file inside your ZIP archive, not the ZIP file itself. For example, if you placed flower.png under the background directory inside your ZIP archive, you can have an InputStream for this file as follows:

 InputStream fileStream = expansionFile.getInputStream("background/flower.png"); 

** EDIT **

I think that the place where you placed your ZIP file is incorrect. According to the Developer's Guide:

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

After successful testing, you can download your extension ZIP file along with the APK through the developer console.

Have you read the APK extension files ? It is pretty simple.

+3
source

Some information for the people who get here in this post, as there are some things that have changed in how the apk extensions work, and also if you use Android Studio to work libraries.

NOTE 1

You can no longer use the draft because the link to the extension file is not yet activated. You must first download the version in Alpha or Beta with the extension file. (adding the extension file is possible only from the second apk file you upload). Therefore, make sure that you see the apk extension file specified when you click details in the developer publishing section of the APK.

NOTE 2

If you are using android studio and want to use the loader library, do not just copy the package name and java files into your own src application directory. Import the bootloader library into eclipse and select export => gradle build files. Subsequently, you can import the library as a module in the Android studio.

NOTE 3

Not sure about this, but I also find it necessary to download the application at least once through the play store and access it with an account on your test device. Therefore, if you work with alpha, create a google + test group and add yourself or other test devices to it.

BTW

With these libraries, it is pretty easy to implement apk download for extension, just make sure:

  • your activity (the one where you want to implement the extension package download when the download was not done automatically) implements IDownloaderClient.

  • You have configured the service and receiver and configured them in your manifest.

  • BASE64_PUBLIC_KEY in the service class is correct. Download first apk => look in services and APIs in the developer console under your application => License code for this application.

This code is used to see if the extension file can be found on the device:

 boolean expansionFilesDelivered() { for (XAPKFile xf : xAPKS) { String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsMain, xf.mFileVersion); Log.i(TAG, "Expansion filename " +fileName); if (!Helpers.doesFileExist(this, fileName, xf.mFileSize, false)) return false; } return true; } 

It uses the XAPKS class, which represents an extension file, whether it is a main file or a patch file having a specific file size (bytes) and associated with the apk version (the one to which it was first added).

 private static class XAPKFile { public final boolean mIsMain; // true public final int mFileVersion; //example 4 public final long mFileSize; //example 126515695L // example => main expansion that was first introduced in apk version 4 and is 126515695 bytes in size XAPKFile(boolean isMain, int fileVersion, long fileSize) { mIsMain = isMain; mFileVersion = fileVersion; mFileSize = fileSize; } } 

It is also quite easy to read movie files and other materials directly from the extension file using the zip tools provided by google (com.android.vending.zipfile).

First, get the extension file using the methods provided in the library, the parameters are integers that represent your main version of the extension apk (the version of apk in which you need to add the extension package) and the version of apk patch.

 ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(context, APKX_MAIN_APK, APKX_PATCH_APK); 

Video

To play videos directly from this zipresourcefile:

 AssetFileDescriptor a = expansionFile.getAssetFileDescriptor(pathToFileInsideZip); 

Now from this FileDescriptor property you can get a FileDescriptor and use it in your media player, the correct syntax for getting a media player for video playback also requires the second and third parameters. Be it the entry level and length that you can get from the AssetFileDescriptor.

 player.setDataSource(a.getFileDescriptor(), a.getStartOffset(), a.getLength()); 

Other

For all other things (like images) you can just get the zipresourcefile input file:

 expansionFile.getInputStream(pathToFileInsideZip);` 

Also, make sure you don't compress the video in zip for this to work! For example, do not compress .mp4 files:

 zip -n .mp4 -r zipfile.zip . -x ".*" -x "*/.*" 
+1
source

Even if it is a zip file, it should still be stored in the obb folder.

0
source

All Articles