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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With