Install encrypted apk apk extension file in Android

I created an encrypted .obb file using the jobb tool. I use the following code to mount the obb file:

public void mountExpansion() { final StorageManager storageManager = (StorageManager) getContext() .getSystemService(Context.STORAGE_SERVICE); String packageName = "name.of.the.package"; String filePath = Environment.getExternalStorageDirectory() + "/Android/obb/" + packageName + "/" + "main." + version + "." + packageName + ".obb"; final File mainFile = new File(filePath); if (mainFile.exists()) { Log.d("STORAGE", "FILE: " + filePath + " Exists"); } else { Log.d("STORAGE", "FILE: " + filePath + " DOESNT EXIST"); } String key = "thisIsMyPassword"; if (!storageManager.isObbMounted(mainFile.getAbsolutePath())) { if (mainFile.exists()) { if(storageManager.mountObb(mainFile.getAbsolutePath(), key, new OnObbStateChangeListener() { @Override public void onObbStateChange(String path, int state) { super.onObbStateChange(path, state); Log.d("PATH = ",path); Log.d("STATE = ", state+""); expansionFilePath = storageManager.getMountedObbPath(path); if (state == OnObbStateChangeListener.MOUNTED) { expansionFilePath = storageManager .getMountedObbPath(path); Log.d("STORAGE","-->MOUNTED"); } else { Log.d("##", "Path: " + path + "; state: " + state); } } })) { Log.d("STORAGE_MNT","SUCCESSFULLY QUEUED"); } else { Log.d("STORAGE_MNT","FAILED"); } } else { Log.d("STORAGE", "Patch file not found"); } } } 

I get the following output: FILE: filePath Exists SUCCESSFUL QUESTIONS

But nothing inside onObbStateChangeListener is called. I call this function from a user view and test it on the Nexus 4 / KitKat.

What could be causing this behavior?

+4
source share
2 answers

There seems to be a bug with installing the OBB that was introduced with KitKat. No workarounds are currently known, however it should be fixed with the next incremental update.

http://code.google.com/p/android/issues/detail?id=61881

+1
source

I know this question is old, but it might help someone else.

StorageManager stores the listener in a weak reference, which means that, given your sample code (an anonymous instance created when the method was called), it disappears almost immediately after its creation and usually long before the mount is complete. You must maintain a reference to the listener object in your own code until it is no longer needed.

Something like this should work:

 public class MyClass { ... private OnObbStateChangeListener mListener = new OnObbStateChangeListener() { @Override public void onObbStateChange(String path, int state) { // your code here } }; public void mountExpansion() { ... if (storageManager.mountObb(mainFile.getAbsolutePath(), key, mListener) { Log.d("STORAGE_MNT","SUCCESSFULLY QUEUED"); } else { Log.d("STORAGE_MNT","FAILED"); } ... } ... } 

This special feature of installing obb exists, at least in cellular, as far as I know.

+7
source

All Articles