How to mount encrypted APK expansion files?

回眸只為那壹抹淺笑 提交于 2019-12-21 17:06:28

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/14342068/how-to-mount-encrypted-apk-expansion-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!