I have developed Application and work successfully.
I have used Application Licensing feature into my application. And now I'm going to upload an application on google play.
Please let me know the steps, How to use Application licensing and how to create APK Expansion file?
First, open the Android SDK Manager (Tools > SDK Manager), and under Appearance & Behavior > System Settings > Android SDK, select the SDK Tools tab to select and download: Google Play Licensing Library package. Google Play APK Expansion Library package.
Set the input directory for creating an OBB file, or the output directory when extracting ( -dump ) an existing file. When creating an OBB file, the contents of the specified directory and all its sub-directories are included in the OBB file system. Specify the filename for the OBB file.
Expansion files are simply files/folders in archived format(. obb to be precise). Google Play allows you to add two large expansion files to a maximum of 2GB for each file. Google Play hosts the expansion files for your application and serves them to the device at no cost to you.
Expansion files remove the restriction of uploading more than 100MB apk size. You should attach these files when uploading the apk. Each app can provide up to 4GB (2GB - main, 2GB - patch) of additional data for each APK.
There are naming convention you have to follow while creating Expansion files
[main|patch].<expansion-version>.<package-name>.obb
note:
main
- are those files without this your application will not going to runpatch
- are those files which are additional, without this your application can runexpansion-version
- version that you are giving to your apk, so that Expansion files of different version will not conflictpackage-name
-This is your unique package name.obb
we are not appending, it will implicitly appended by Google while uploading
suppose you have all the content in your current directory so just select all the content and make it a zip named main.2.com.xyz.abc.zip
and attach it with while uploading apk
This all uploading part, now downloading part
First of all you need to download Google extra package by clicking on SDK-Manager
Now create new project from existing source and import market_licensing, play_apk_expansion from the path sdk-path/extras/google
Remember: Free app does not require Licensing but Expansion concept required, you just need not to bother by giving reference of market_licensing to your project it will implicitly manage.
play_apk_expansion
contains three projects downloader_library
, zip_file
, downloader_sample
.
downloader_library itself having the reference of Market_licensing.
Now you just need to concentrate on downloader_sample
first change the package name(for testing) to your packagename(packagename same as uploaded apk)
Very Important
In SampleDownloaderActivity
navigate to...
private static final XAPKFile[] xAPKS = { new XAPKFile( true, // true signifies a main file 2, // the version of the APK that the file was uploaded // against xxxxxxxxxxxL // the length of the zipfile in bytes right click on you expansion file and get the size in bytes, size must be same as zip size ), };
Now This activity will download the Expansion file and will store it in sdcard/Android/obb/[main|patch].<expansion-version>.<package-name>.obb
ignore obb, just unzip this file anywhere you want (sdcard/Android/data
recommended because it removes when your application get uninstalled).
There are latest device which download Expansion files directly from Play store and it get stored in sdcard/Android/obb/
so you have to be very careful to check all the cases
Memory Cases:
if you take any new device or for ex. micromax funbook, then it's having three memory
Hope this will help you and will meet your requirements.
And one more thing use this below ZipHelper
to unzipped the content.
ZipHelper.java
public class ZipHelper { boolean zipError=false; public boolean isZipError() { return zipError; } public void setZipError(boolean zipError) { this.zipError = zipError; } public void unzip(String archive, File outputDir) { try { Log.d("control","ZipHelper.unzip() - File: " + archive); ZipFile zipfile = new ZipFile(archive); for (Enumeration e = zipfile.entries(); e.hasMoreElements(); ) { ZipEntry entry = (ZipEntry) e.nextElement(); unzipEntry(zipfile, entry, outputDir); } } catch (Exception e) { Log.d("control","ZipHelper.unzip() - Error extracting file " + archive+": "+ e); setZipError(true); } } private void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException { if (entry.isDirectory()) { createDirectory(new File(outputDir, entry.getName())); return; } File outputFile = new File(outputDir, entry.getName()); if (!outputFile.getParentFile().exists()){ createDirectory(outputFile.getParentFile()); } Log.d("control","ZipHelper.unzipEntry() - Extracting: " + entry); BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); try { IOUtils.copy(inputStream, outputStream); } catch (Exception e) { Log.d("control","ZipHelper.unzipEntry() - Error: " + e); setZipError(true); } finally { outputStream.close(); inputStream.close(); } } private void createDirectory(File dir) { Log.d("control","ZipHelper.createDir() - Creating directory: "+dir.getName()); if (!dir.exists()){ if(!dir.mkdirs()) throw new RuntimeException("Can't create directory "+dir); } else Log.d("control","ZipHelper.createDir() - Exists directory: "+dir.getName()); } }
First , assume you are migrate using a helloworld.jpg from /assets/helloworld.jpg to your expansion
`[main|patch].{expansion-version}.{package-name}.obb`
E.g if your pkg name is "com.earth.helloworld" and version = 1
then your output extension file name should be: patch.1.com.earth.helloworld.obb
which is a zip file containing helloworld.jpg
after the zip file is created, note the file size: 2. then create this folder on your sdcard if not exists:
/mnt/sdcard/Android/obb/{your package name}/
i.e /mnt/sdcard/Android/obb/com.earth.helloworld/
then upload your obb file to your sdcard e.g /mnt/sdcard/Android/obb/com.earth.helloworld/patch.1.com.earth.helloworld.obb
Then create a method to get the extension file
public ZipResourceFile getExpansionFile() { String fileName = Helpers.getExpansionAPKFileName(this, false, 1); int filesize = 445461159; if (Helpers.doesFileExist(this, fileName, , false)) { try { return APKExpansionSupport.getAPKExpansionZipFile( getBaseContext(), 1, 1); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; }
Finally use this two lines to get the helloworld.jpgInputStream istr = getExpansionFile().getInputStream(strName);
Bitmap bitmap = BitmapFactory.decodeStream(istr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With