My Android Expansion File Downloder is not working. I found out, that the problem occurs in the original DownloadThread.java I have verified that that external media is mounted.
The passed data is correct: byte[] data contains bytesRead = 4096 Bytes. These are checked and were correctly read from the expected obb file. Also state.filename is absolutely correct. state.mStream = null, therefore a FileOutputStream must be opened first.
new FileOutputStream(state.mFilename, true) produces an IOException
private void writeDataToDestination(State state, byte[] data, int bytesRead)
throws StopRequest {
for (;;) {
try {
if (state.mStream == null) {
state.mStream = new FileOutputStream(state.mFilename, true);
}
state.mStream.write(data, 0, bytesRead);
// we close after every write --- this may be too inefficient
closeDestination(state);
return;
} catch (IOException ex) {
if (!Helpers.isExternalMediaMounted()) {
throw new StopRequest(DownloaderService.STATUS_DEVICE_NOT_FOUND_ERROR,
"external media not mounted while writing destination file");
}
The WRITE_EXTERNAL_STORAGE permission should be given: AndroidManifest.xml:
...
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
...
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name_short"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:preserveLegacyExternalStorage="true"
android:theme="@style/AppTheme">
...
And my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
useLibrary 'org.apache.http.legacy'
signingConfigs {
Signed {
keyAlias ...
keyPassword ...
storeFile file(...)
storePassword ...
}
}
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
ndk {
debugSymbolLevel 'FULL'
}
}
...
I'm totally stuck and can't continue. What can I do?