Skip to content

Commit

Permalink
Merge pull request #607 from a-koka/master
Browse files Browse the repository at this point in the history
getContentLengthLong requires API 24
  • Loading branch information
itinance authored Dec 21, 2018
2 parents b6b3758 + 48eca16 commit 40e59c2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions android/src/main/java/com/rnfs/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
connection.connect();

int statusCode = connection.getResponseCode();
long lengthOfFile = connection.getContentLengthLong();
long lengthOfFile = getContentLength(connection);

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

statusCode = connection.getResponseCode();
lengthOfFile = connection.getContentLengthLong();
lengthOfFile = getContentLength(connection);
}
if(statusCode >= 200 && statusCode < 300) {
Map<String, List<String>> headers = connection.getHeaderFields();
Expand Down Expand Up @@ -141,6 +141,13 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
}
}

private long getContentLength(HttpURLConnection connection){
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
return connection.getContentLengthLong();
}
return connection.getContentLength();
}

protected void stop() {
mAbort.set(true);
}
Expand Down

0 comments on commit 40e59c2

Please sign in to comment.