私は同じ問題を抱えていましたが、それを解決する方法を見つけました。
OBB を削除すると、dosFileExist (Helpers.java 内) は false を返します。ExpansionFilesDelivered をチェックする ExpDownloaderActivity で、この情報を使用して OBB を再ダウンロードします。
ブール値ではなく、次の意味を持つ整数を返すように、dosFileExist と ExpansionFilesDelivered を変更しました。
fileStatus == 0: OBB がありません (ダウンロードする必要があります)
fileStatus == 1: OBB が利用可能で、別の場所に解凍できます
fileStatus == 2: OBB のデータは既に別の場所に保存されています
ここでのトリック: OBB からお気に入りの場所にデータを解凍した後、元の OBB を、元の OBB のファイルサイズのみを文字列として含む同じ名前のファイルに置き換えます。これにより、sdcard の占有スペースが解放されます。
doesFileExist と ExpansionFilesDelivered をさらに呼び出すと、filestatus = 2 が返されます。これは、アクションが必要ないことを意味します。
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;
}
OBB のファイル サイズが一致しない場合は、OBB を読み取り、内部に格納されているファイル サイズと比較します (これはファイル サイズであってはなりません)。これが一致する場合、ファイルは既に処理されていることがわかります。
これは私の 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;
}
ExpDownloaderActivity の onCreate で:
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 }
したがって、OPが述べたように、完全なOBBとアンパックされたデータ用のsdcard上のスペースは必要ありません。