|
@@ -1,9 +1,13 @@
|
1
|
1
|
package com.RNFetchBlob;
|
2
|
2
|
|
|
3
|
+import android.app.DownloadManager;
|
|
4
|
+import android.content.Context;
|
|
5
|
+
|
3
|
6
|
import com.facebook.react.bridge.Arguments;
|
4
|
7
|
import com.facebook.react.bridge.Callback;
|
5
|
8
|
import com.facebook.react.bridge.ReactApplicationContext;
|
6
|
9
|
import com.facebook.react.bridge.ReactContext;
|
|
10
|
+import com.facebook.react.bridge.ReadableMap;
|
7
|
11
|
import com.facebook.react.bridge.WritableMap;
|
8
|
12
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
9
|
13
|
import com.loopj.android.http.FileAsyncHttpResponseHandler;
|
|
@@ -61,6 +65,26 @@ public class RNFetchBlobFileHandler extends FileAsyncHttpResponseHandler {
|
61
|
65
|
|
62
|
66
|
@Override
|
63
|
67
|
public void onSuccess(int statusCode, Header[] headers, File file) {
|
|
68
|
+ ReadableMap notifyConfig = mConfig.addAndroidDownloads;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+ if(notifyConfig != null ) {
|
|
72
|
+ String title = "", desc = "", mime = "text/plain";
|
|
73
|
+ boolean scannable = false, notification = false;
|
|
74
|
+ if(notifyConfig.hasKey("title"))
|
|
75
|
+ title = mConfig.addAndroidDownloads.getString("title");
|
|
76
|
+ if(notifyConfig.hasKey("description"))
|
|
77
|
+ desc = notifyConfig.getString("description");
|
|
78
|
+ if(notifyConfig.hasKey("mime"))
|
|
79
|
+ mime = notifyConfig.getString("mime");
|
|
80
|
+ if(notifyConfig.hasKey("mediaScannable"))
|
|
81
|
+ scannable = notifyConfig.getBoolean("mediaScannable");
|
|
82
|
+ if(notifyConfig.hasKey("notification"))
|
|
83
|
+ notification = notifyConfig.getBoolean("notification");
|
|
84
|
+ DownloadManager dm = (DownloadManager)mCtx.getSystemService(mCtx.DOWNLOAD_SERVICE);
|
|
85
|
+ dm.addCompletedDownload(title, desc, scannable, mime, file.getAbsolutePath(), file.length(), notification);
|
|
86
|
+ }
|
|
87
|
+
|
64
|
88
|
this.onResponse.invoke(null, file.getAbsolutePath());
|
65
|
89
|
}
|
66
|
90
|
}
|