5

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?

uncle Lem
  • 4,954
  • 8
  • 33
  • 53
  • Well, I haven't found how to mount encrypted obb file, but using non-encrypted obb works fine. – uncle Lem Feb 04 '13 at 13:03
  • hello uncle Lem, Here i am facing same state-21, so please give me an example how can i using non-encrypted obb – Krunal Shah Sep 19 '15 at 05:33
  • 2
    @KrunalShah I created util class to manage obb, please see https://github.com/uncleLem/AndroidUtils/blob/master/src/io/github/unclelem/androidutils/utils/ObbExpansionsManager.java You can also find some details in my other answer: http://stackoverflow.com/questions/14685315/how-to-create-obb-files-using-jobb-tool-android/14687592#14687592 – uncle Lem Sep 19 '15 at 12:23

1 Answers1

3

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.

brachialste
  • 105
  • 2
  • 11
  • 1
    In this case `user` and `group` are generic , you have to try with any valid user of your Linux instalation where youre trying to build with the AOSP files. – brachialste May 20 '13 at 18:44