Skip to content

Commit 40e59c2

Browse files
authored
Merge pull request #607 from a-koka/master
getContentLengthLong requires API 24
2 parents b6b3758 + 48eca16 commit 40e59c2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

android/src/main/java/com/rnfs/Downloader.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
6464
connection.connect();
6565

6666
int statusCode = connection.getResponseCode();
67-
long lengthOfFile = connection.getContentLengthLong();
67+
long lengthOfFile = getContentLength(connection);
6868

6969
boolean isRedirect = (
7070
statusCode != HttpURLConnection.HTTP_OK &&
@@ -85,7 +85,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
8585
connection.connect();
8686

8787
statusCode = connection.getResponseCode();
88-
lengthOfFile = connection.getContentLengthLong();
88+
lengthOfFile = getContentLength(connection);
8989
}
9090
if(statusCode >= 200 && statusCode < 300) {
9191
Map<String, List<String>> headers = connection.getHeaderFields();
@@ -141,6 +141,13 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
141141
}
142142
}
143143

144+
private long getContentLength(HttpURLConnection connection){
145+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
146+
return connection.getContentLengthLong();
147+
}
148+
return connection.getContentLength();
149+
}
150+
144151
protected void stop() {
145152
mAbort.set(true);
146153
}

0 commit comments

Comments
 (0)