I had the same problem but I've found a way to solve it.
If you delete the OBB, then doesFileExist (in Helpers.java) will return false. In your ExpDownloaderActivity, where you check expansionFilesDelivered, you will use this information to re-download the OBB.
I've changed the doesFileExist and expansionFilesDelivered in a way not to return a boolean but an integer with the following meaning:
fileStatus == 0: OBB is missing (must be downloaded)
fileStatus == 1: OBB is available and can be unpacked to another place
fileStatus == 2: data in OBB is already stored to another place
Now te trick:
After unpacking the data from OBB to my favorite place, I replace the original OBB with a file with the same name that contains only the filesize of the original OBB as a string. This frees up the occupied space on sdcard.
Further calls to doesFileExist and expansionFilesDelivered will return filestatus = 2 which means, there is no action required.
Here are my changes in Helpers.java:
static public int doesFileExist(Context c, String fileName, long fileSize,
boolean deleteFileOnMismatch) {
// the file may have been delivered by Market --- let's make sure
// it's the size we expect
File fileForNewFile = new File(Helpers.generateSaveFileName(c, fileName));
if (fileForNewFile.exists()) {
if (fileForNewFile.length() == fileSize) {
return 1;
} else if (fileForNewFile.length() < 100) {
// Read the file and look for the file size inside
String content = "";
long isSize = 0;
FileInputStream fis = null;
try {
fis = new FileInputStream(fileForNewFile);
char current;
while (fis.available() > 0) {
current = (char) fis.read();
content = content + String.valueOf(current);
}
} catch (Exception e) {
Log.d("ReadOBB", e.toString());
} finally {
if (fis != null)
try {
fis.close();
} catch (IOException ignored) {
}
}
try {
isSize = Long.parseLong(content);
} catch(NumberFormatException nfe) {
Log.d("ReadOBBtoInt", nfe.toString());
}
if (isSize == fileSize) {
return 2;
}
}
if (deleteFileOnMismatch) {
// delete the file --- we won't be able to resume
// because we cannot confirm the integrity of the file
fileForNewFile.delete();
}
}
return 0;
}
If the file size of the OBB not match, I read the OBB and compare with the filesize stored inside (this is what the filesize shouldt be). If this give a match, I know that the file is already processed.
This are my changes in my ExpDownloaderActivity:
int expansionFilesDelivered() {
int fileStatus = 0;
for (XAPKFile xf : xAPKS) {
if (xf.mFileSize > 0) {
String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsMain, xf.mFileVersion);
fileStatus = Helpers.doesFileExist(this, fileName, xf.mFileSize, false);
if (fileStatus==0)
return 0;
}
}
return fileStatus;
}
In the onCreate of the ExpDownloaderActivity:
initializeDownloadUI();
int fileStatus = expansionFilesDelivered();
if (fileStatus==0) { // OBB is missing
// ... Download the OBB file, same as on Downloader example
} else if (fileStatus==1) {
validateXAPKZipFiles(); // and, if OBB has no errors, unpack it to my favorite place
// if done, create a new OBB file with the original name
// and store a string with the original filesize in it.
} else {
finish(); // No action required }
So I have the data unpacked wherever I want and - as the OP mentioned - no need the space on sdcard for the full OBB and the unpacked data.