How to extract files from .obb file?

13,171

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 .

Share:
13,171
Lorenzo Salani
Author by

Lorenzo Salani

Updated on June 28, 2022

Comments

  • Lorenzo Salani
    Lorenzo Salani about 2 years

    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 .