diff --git a/android/src/main/java/com/rnfs/Downloader.java b/android/src/main/java/com/rnfs/Downloader.java index 2866d0cd..3764bd17 100644 --- a/android/src/main/java/com/rnfs/Downloader.java +++ b/android/src/main/java/com/rnfs/Downloader.java @@ -64,7 +64,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception connection.connect(); int statusCode = connection.getResponseCode(); - int lengthOfFile = connection.getContentLength(); + long lengthOfFile = getContentLength(connection); boolean isRedirect = ( statusCode != HttpURLConnection.HTTP_OK && @@ -85,7 +85,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception connection.connect(); statusCode = connection.getResponseCode(); - lengthOfFile = connection.getContentLength(); + lengthOfFile = getContentLength(connection); } if(statusCode >= 200 && statusCode < 300) { Map> headers = connection.getHeaderFields(); @@ -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); }