Skip to content Skip to sidebar Skip to footer

Is There A Way To Manually Create The Package Folder For An Apk's .obb File?

I'm having an issue with an app: (rarely) a user will download the app from the play store but the obb/expansion file will fail to download. If the folder for the obb file is creat

Solution 1:

The Context::getObbDir() method allows access to the expansion folder without the usual security rules. I found that, if the folder doesn't exist, getObbDir() creates it too (You can also double check create it manually with mkdir()).

Excerpt from the documentation linked above:

Return the primary shared/external storage directory where this application's OBB files (if there are any) can be found. Note if the application does not have any OBB files, this directory may not exist.

This is like getFilesDir() in that these files will be deleted when the application is uninstalled, however there are some important differences:

... Starting in Build.VERSION_CODES.KITKAT, no permissions are required to read or write to the path that this method returns. ...

Starting from Build.VERSION_CODES.N, Manifest.permission.READ_EXTERNAL_STORAGE permission is not required, so don’t ask for this permission at runtime. ...

So the code in the question can become:

FileobbDir= getObbDir();

if (null == obbDir) {
    // Storage is not available
} elseif (!obbDir.exists() && !obbDir.mkdir()) {
    // Failed to create directory. Shouldn't happen but you never know.
}

NOTE: You may need the read/write permissions to access the expansion files within the folder. See the documentation for more info.

Post a Comment for "Is There A Way To Manually Create The Package Folder For An Apk's .obb File?"