Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit ecf7e2c

Browse files
committed
Add implementation of #22
1 parent e5364c6 commit ecf7e2c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.RNFetchBlob;
22

3+
import android.app.DownloadManager;
4+
import android.content.Context;
35
import android.net.Uri;
46
import android.os.Environment;
57

@@ -159,6 +161,30 @@ public void fetchBlob(ReadableMap options, String taskId, String method, String
159161

160162
RNFetchBlobConfig config = new RNFetchBlobConfig(options);
161163

164+
// use download manager instead of default HTTP implementation
165+
if(config.addAndroidDownloads != null && config.addAndroidDownloads.hasKey("useDownloadManager")) {
166+
167+
if(config.addAndroidDownloads.getBoolean("useDownloadManager")) {
168+
Uri uri = Uri.parse(url);
169+
DownloadManager.Request req = new DownloadManager.Request(uri);
170+
if(config.path != null) {
171+
Uri dest = null;
172+
dest = Uri.parse(config.path);
173+
req.setDestinationUri(dest);
174+
}
175+
// set headers
176+
ReadableMapKeySetIterator it = headers.keySetIterator();
177+
while (it.hasNextKey()) {
178+
String key = it.nextKey();
179+
req.addRequestHeader(key, headers.getString(key));
180+
}
181+
DownloadManager dm = (DownloadManager) this.getReactApplicationContext().getSystemService(Context.DOWNLOAD_SERVICE);
182+
dm.enqueue(req);
183+
return;
184+
}
185+
186+
}
187+
162188
try {
163189
AsyncHttpClient req = new AsyncHttpClient();
164190

0 commit comments

Comments
 (0)