Code example for StorageManager

Methods: getMountedObbPathisObbMountedmountObb

0
        patchFile = new File(Environment.getExternalStorageDirectory() + "/Android/obb/" + packageName + "/" 
                + "patch." + packageVersion + "." + packageName + ".obb"); 
        mainFile = new File(Environment.getExternalStorageDirectory() + "/Android/obb/" + packageName + "/" 
                + "main." + packageVersion + "." + packageName + ".obb"); 
 
        Log.d(TAG, "Check if path file already mounted: " + sm.isObbMounted(patchFile.getAbsolutePath())); 
        if (sm.isObbMounted(patchFile.getAbsolutePath())) { 
            Log.d(TAG, "Patch file already mounted. Unmounting..."); 
            sm.unmountObb(patchFile.getAbsolutePath(), true, new OnObbStateChangeListener() { 
                @Override 
                public void onObbStateChange(String path, int state) { 
                    super.onObbStateChange(path, state); 
                    if (state == UNMOUNTED) { 
                        Log.d(TAG, "Patch file successfully unmounted."); 
                        mountPatch(); 
                    } 
                } 
            }); 
        } else { 
            mountPatch(); 
        } 
 
        Log.d(TAG, "Check if main file already mounted: " + sm.isObbMounted(mainFile.getAbsolutePath())); 
        if (sm.isObbMounted(mainFile.getAbsolutePath())) { 
            Log.d(TAG, "Main file already mounted. Unmounting..."); 
            sm.unmountObb(mainFile.getAbsolutePath(), true, new OnObbStateChangeListener() { 
                @Override 
                public void onObbStateChange(String path, int state) {
                    super.onObbStateChange(path, state);
                    if (state == UNMOUNTED) {
                        Log.d(TAG, "Main file successfully unmounted.");
                        mountMain(); 
                    } 
                } 
            }); 
        } else { 
            mountMain(); 
        } 
 
        if (!mainFile.exists() && !patchFile.exists()) { 
            Log.d(TAG, "No expansion files found!"); 
            listener.onFilesNotFound(); 
        } 
    } 
 
    private void mountPatch() { 
        if (patchFile.exists()) {
            Log.d(TAG, "Mounting patch file...");
            sm.mountObb(patchFile.getAbsolutePath(), null, new OnObbStateChangeListener() {
                @Override 
                public void onObbStateChange(String path, int state) {
                    super.onObbStateChange(path, state);
                    if (state == MOUNTED) {
                        Log.d(TAG, "Mounting patch file done.");
                        patch = sm.getMountedObbPath(patchFile.getAbsolutePath());
                    } else { 
                        Log.d(TAG, "Mounting patch file failed with state = " + state);
                        listener.onObbStateChange(path, state);
                    } 
                } 
            }); 
            if (sm.isObbMounted(patchFile.getAbsolutePath())) {
                patch = sm.getMountedObbPath(patchFile.getAbsolutePath());
                listener.onMountSuccess();
            } 
        } else { 
            Log.d(TAG, "Patch file not found");
        } 
    } 
 
    private void mountMain() { 
        if (mainFile.exists()) {
            Log.d(TAG, "Mounting main file...");
            Log.d(TAG, "Scheduling mount checker...");
            (new Timer()).schedule(mainChecker, 1000);
            sm.mountObb(mainFile.getAbsolutePath(), null, new OnObbStateChangeListener() {
                @Override 
                public void onObbStateChange(String path, int state) {
                    super.onObbStateChange(path, state);
                    if (state == MOUNTED) {
                        Log.d(TAG, "Mounting main file done.");