Skip to content

Commit

Permalink
add file extension detect
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLYC committed Jul 3, 2019
1 parent 18c7a94 commit 52dbc8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ext {
'targetSdkVersion' : 28,
'minSdkVersion' : 19,
'versionCode' : 1,
'versionName' : '0.7.0-beta'
'versionName' : '0.7.1-beta'
]
deps = [
'kotlin-stdlib' : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version",
Expand Down
16 changes: 16 additions & 0 deletions downloader/src/main/java/com/lyc/downloader/DownloadTask.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lyc.downloader;

import android.util.SparseArray;
import android.webkit.MimeTypeMap;
import androidx.annotation.IntDef;
import androidx.annotation.WorkerThread;
import com.lyc.downloader.db.DownloadInfo;
Expand Down Expand Up @@ -189,6 +190,21 @@ private InputStream doPivotCall() {
if (filename.isEmpty()) {
filename = Constants.UNKNOWN_FILE_NAME;
}
MediaType mediaType = body.contentType();
String extension;
if (mediaType != null) {
extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mediaType.toString());
} else {
extension = MimeTypeMap.getFileExtensionFromUrl(response.request().url().toString());
}

if (extension != null && !filename.endsWith(extension)) {
if (filename.endsWith(".")) {
filename = filename + extension;
} else {
filename = filename + "." + extension;
}
}
}


Expand Down

0 comments on commit 52dbc8e

Please sign in to comment.