3

in my application I downloaded the expansion file at Android->obb->packagename->main.1.packagename.obb . Can someone explain to me, even with the sample code how to extract my files from it ?

I tried to use the APK Expansion Zip Library as :

ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(MainActivity.this, 3, 0);  
for (ZipResourceFile.ZipEntryRO entry : expansionFile.getAllEntries())
Log.d("",entry.mFileName);
InputStream input = expansionFile.getInputStream(Environment.getExternalStorageDirectory().toString()
                            + "/sdcard/Android/obb/com.example.project/main.3.com.example.project.obb/obb/file.zip/file.apk");

But expansionFile is always null. The .obb file was created with Jobb, used on the folder obb/file.zip .

Lorenzo Salani
  • 73
  • 1
  • 1
  • 7
  • What have you tried so far? The [APK Expansion Documentation](http://developer.android.com/google/play/expansion-files.html) is actually pretty good. – Khalos Jul 13 '15 at 22:35

2 Answers2

1

Solved with the following code:

    final StorageManager storageManager = (StorageManager) getSystemService(STORAGE_SERVICE);
    String obbPath = Environment.getExternalStorageDirectory() + "/Android/obb";
    final String obbFilePath = obbPath + "/com.example.project/main.3.com.example.project.obb";
    OnObbStateChangeListener mount_listener = new OnObbStateChangeListener() {
          public void onObbStateChange(String path, int state) {
                if (state == OnObbStateChangeListener.MOUNTED) {
                      if (storageManager.isObbMounted(obbFilePath)) {
                            Log.d("Main","Mounted successful");
                            String newPath  = storageManager.getMountedObbPath(obbFilePath);
                            File expPath = new File(newPath+"/file.zip/file.apk");
                            Log.d("Main","File exist: " + expPath.exists());
                      }
                }
          }
    };
    storageManager.mountObb(obbFilePath, "key", mount_listener);

After mounting the .obb file , I can access my data in the path mnt/obb/myfolder .

Lorenzo Salani
  • 73
  • 1
  • 1
  • 7
0

I used this for reading a specific file from the obb:

In your AndroidManifest.xml:

<!-- Needed for reading the obb file -->
<provider
    android:name=".extension.ZipFileContentProvider"
    android:authorities="com.example.extension.ZipFileContentProvider"/>

ZipFileContentProvider:

public class ZipFileContentProvider extends APEZProvider {
  @Override
  public String getAuthority() {
    return "com.example.extension.ZipFileContentProvider";
  }
}

Get file URI:

final Uri CONTENT_URI = Uri.parse("content://" + "com.example.extension.ZipFileContentProvider");
Uri uri = Uri.parse(CONTENT_URI + "/drawable/" + name)

To create the obb file i used a gradle script (the res folder is in the same directory):

task createExpansionFile(type: Zip) {
  from 'res'

  entryCompression = ZipEntryCompression.STORED
  archiveName = 'main' + '.' + '1' + '.' + 'com.example' + '.obb'

  println archiveName
  println relativePath(destinationDir)
  println relativePath(archivePath)
}