如何挂载加密的APK扩展文件?

时间:2013-01-15 16:19:57

标签: android apk-expansion-files

我尝试以这种方式挂载扩展文件:

    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);
            }
        }
    });

但在运行时我得到状态21:ERROR_COULD_NOT_MOUNT:

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

我已经添加了这个:

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

并且logcat说该文件存在。我不知道,为什么我能得到这个状态21?

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,我想通过obb上的Linux文件权限很多次Error 21,而问题是Android无法访问它,因此StorageManager启动Error 21。创建.obb文件时,将权限和用户组更改为文件,如:

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

然后再试一次,为我工作。