Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mount encrypted APK expansion files?

I tried to mount expansion files this way:

    final StorageManager storageManager = (StorageManager) getSystemService(STORAGE_SERVICE);
    String obbPath = Environment.getExternalStorageDirectory() + "/Android/obb";
    final String obbFilePath = obbPath + "/com.example/main.1.com.example.obb";
    storageManager.mountObb(obbFilePath, "SecretKey", new OnObbStateChangeListener() {
        @Override
        public void onObbStateChange(String path, int state) {
            super.onObbStateChange(path, state);
            if (state == OnObbStateChangeListener.MOUNTED) {
                onObbMounted();
            } else {
                Log.d("##", "Path: " + path + "; state: " + state);
            }
        }
    });

But in runtime I'm getting state 21: ERROR_COULD_NOT_MOUNT:

Path: /storage/sdcard0/Android/obb/com.example/main.1.com.example.obb; state: 21

I've added this:

    File f = new File(obbFilePath);
    if (!f.exists()) {
        Log.e("OBB", "FILE NOT FOUND!!!");
    }

And logcat says that file exist. I have no idea, why I can get this state 21?

like image 953
uncle Lem Avatar asked Oct 21 '22 19:10

uncle Lem


1 Answers

I had the same problem, and i figured aout that many times Error 21 is casued by Linux Files Permissions over the obb, and the problem is that Android cannot have access to it so the StorageManager launches Error 21. When you create the .obb file, change permissions and user group to the file, something like:

$chmod 664 <obb-filename>.obb    
$chown user:group <obb-filename>.obb

Then try again, worked for me.

like image 116
brachialste Avatar answered Nov 01 '22 11:11

brachialste