@kesha-antonov/react-native-background-downloader 3.2.1 → 3.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -214,6 +214,7 @@ An object containing options properties
|
|
|
214
214
|
| `isAllowedOverRoaming` | Boolean | | Android | whether this download may proceed over a roaming connection. By default, roaming is allowed |
|
|
215
215
|
| `isAllowedOverMetered` | Boolean | | Android | Whether this download may proceed over a metered network connection. By default, metered networks are allowed |
|
|
216
216
|
| `isNotificationVisible` | Boolean | | Android | Whether to show a download notification or not |
|
|
217
|
+
| `notificationTitle` | String | | Android | Title of the download notification |
|
|
217
218
|
|
|
218
219
|
**returns**
|
|
219
220
|
|
package/android/build.gradle
CHANGED
|
@@ -7,13 +7,15 @@ public class RNBGDTaskConfig implements Serializable {
|
|
|
7
7
|
public String url;
|
|
8
8
|
public String destination;
|
|
9
9
|
public String metadata = "{}";
|
|
10
|
+
public String notificationTitle;
|
|
10
11
|
public boolean reportedBegin;
|
|
11
12
|
|
|
12
|
-
public RNBGDTaskConfig(String id, String url, String destination, String metadata) {
|
|
13
|
+
public RNBGDTaskConfig(String id, String url, String destination, String metadata, String notificationTitle) {
|
|
13
14
|
this.id = id;
|
|
14
15
|
this.url = url;
|
|
15
16
|
this.destination = destination;
|
|
16
17
|
this.metadata = metadata;
|
|
18
|
+
this.notificationTitle = notificationTitle;
|
|
17
19
|
this.reportedBegin = false;
|
|
18
20
|
}
|
|
19
21
|
}
|
|
@@ -189,10 +189,18 @@ public class RNBackgroundDownloaderModule extends ReactContextBaseJavaModule {
|
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
compatRegisterReceiver(context, downloadReceiver, filter, true);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// TAKEN FROM
|
|
196
|
+
// https://github.com/facebook/react-native/pull/38256/files#diff-d5e21477eeadeb0c536d5870f487a8528f9a16ae928c397fec7b255805cc8ad3
|
|
197
|
+
private void compatRegisterReceiver(Context context, BroadcastReceiver receiver, IntentFilter filter,
|
|
198
|
+
boolean exported) {
|
|
199
|
+
if (Build.VERSION.SDK_INT >= 34 && context.getApplicationInfo().targetSdkVersion >= 34) {
|
|
200
|
+
context.registerReceiver(
|
|
201
|
+
receiver, filter, exported ? Context.RECEIVER_EXPORTED : Context.RECEIVER_NOT_EXPORTED);
|
|
194
202
|
} else {
|
|
195
|
-
context.registerReceiver(
|
|
203
|
+
context.registerReceiver(receiver, filter);
|
|
196
204
|
}
|
|
197
205
|
}
|
|
198
206
|
|
|
@@ -250,6 +258,7 @@ public class RNBackgroundDownloaderModule extends ReactContextBaseJavaModule {
|
|
|
250
258
|
String destination = options.getString("destination");
|
|
251
259
|
ReadableMap headers = options.getMap("headers");
|
|
252
260
|
String metadata = options.getString("metadata");
|
|
261
|
+
String notificationTitle = options.getString("notificationTitle");
|
|
253
262
|
int progressIntervalScope = options.getInt("progressInterval");
|
|
254
263
|
if (progressIntervalScope > 0) {
|
|
255
264
|
progressInterval = progressIntervalScope;
|
|
@@ -273,6 +282,10 @@ public class RNBackgroundDownloaderModule extends ReactContextBaseJavaModule {
|
|
|
273
282
|
request.setRequiresCharging(false);
|
|
274
283
|
}
|
|
275
284
|
|
|
285
|
+
if (notificationTitle != null) {
|
|
286
|
+
request.setTitle(notificationTitle);
|
|
287
|
+
}
|
|
288
|
+
|
|
276
289
|
if (headers != null) {
|
|
277
290
|
ReadableMapKeySetIterator iterator = headers.keySetIterator();
|
|
278
291
|
while (iterator.hasNextKey()) {
|
|
@@ -287,7 +300,7 @@ public class RNBackgroundDownloaderModule extends ReactContextBaseJavaModule {
|
|
|
287
300
|
request.setDestinationInExternalFilesDir(this.getReactApplicationContext(), null, filename);
|
|
288
301
|
|
|
289
302
|
long downloadId = downloader.download(request);
|
|
290
|
-
RNBGDTaskConfig config = new RNBGDTaskConfig(id, url, destination, metadata);
|
|
303
|
+
RNBGDTaskConfig config = new RNBGDTaskConfig(id, url, destination, metadata, notificationTitle);
|
|
291
304
|
|
|
292
305
|
synchronized (sharedLock) {
|
|
293
306
|
configIdToDownloadId.put(id, downloadId);
|
|
@@ -485,11 +498,18 @@ public class RNBackgroundDownloaderModule extends ReactContextBaseJavaModule {
|
|
|
485
498
|
|
|
486
499
|
private void loadDownloadIdToConfigMap() {
|
|
487
500
|
synchronized (sharedLock) {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
501
|
+
try {
|
|
502
|
+
String str = mmkv.decodeString(getName() + "_downloadIdToConfig");
|
|
503
|
+
if (str != null) {
|
|
504
|
+
Gson gson = new Gson();
|
|
505
|
+
|
|
506
|
+
TypeToken<Map<Long, RNBGDTaskConfig>> mapType = new TypeToken<Map<Long, RNBGDTaskConfig>>() {
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
downloadIdToConfig = (Map<Long, RNBGDTaskConfig>) gson.fromJson(str, mapType);
|
|
510
|
+
}
|
|
511
|
+
} catch (Exception e) {
|
|
512
|
+
Log.e(getName(), "loadDownloadIdToConfigMap: " + Log.getStackTraceString(e));
|
|
493
513
|
}
|
|
494
514
|
}
|
|
495
515
|
}
|
package/index.d.ts
CHANGED
|
@@ -112,6 +112,7 @@ export interface DownloadOption {
|
|
|
112
112
|
isAllowedOverRoaming?: boolean;
|
|
113
113
|
isAllowedOverMetered?: boolean;
|
|
114
114
|
isNotificationVisible?: boolean;
|
|
115
|
+
notificationTitle?: string;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
export type Download = (options: DownloadOption) => DownloadTask;
|
package/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kesha-antonov/react-native-background-downloader",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.3",
|
|
4
4
|
"description": "A library for React-Native to help you download large files on iOS and Android both in the foreground and most importantly in the background.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|