Add showNotification option on android

This commit is contained in:
2024-01-27 22:29:38 +01:00
parent ec1a172cca
commit 3c1b703c80
4 changed files with 6 additions and 1 deletions

View File

@@ -215,6 +215,7 @@ An object containing options properties
| `headers` | Object | | All | Costume headers to add to the download request. These are merged with the headers given in the `setConfig({ headers: { ... } })` function |
| `isAllowedOverRoaming` | Boolean | | Android | whether this download may proceed over a roaming connection. By default, roaming is allowed |
| `isAllowedOverMetered` | Boolean | | Android | Whether this download may proceed over a metered network connection. By default, metered networks are allowed |
| `showNotification` | Boolean | | Android | Whether to show a download notification or not |
**returns**

View File

@@ -361,6 +361,7 @@ public class RNBackgroundDownloaderModule extends ReactContextBaseJavaModule {
boolean isAllowedOverRoaming = options.getBoolean("isAllowedOverRoaming");
boolean isAllowedOverMetered = options.getBoolean("isAllowedOverMetered");
boolean showNotification = options.getBoolean("showNotification");
if (id == null || url == null || destination == null) {
Log.e(getName(), "id, url and destination must be set");
@@ -371,7 +372,7 @@ public class RNBackgroundDownloaderModule extends ReactContextBaseJavaModule {
final Request request = new Request(Uri.parse(url));
request.setAllowedOverRoaming(isAllowedOverRoaming);
request.setAllowedOverMetered(isAllowedOverMetered);
request.setNotificationVisibility(Request.VISIBILITY_HIDDEN);
request.setNotificationVisibility(showNotification ? Request.VISIBILITY_VISIBLE : Request.VISIBILITY_HIDDEN);
request.setRequiresCharging(false);
int uuid = (int) (System.currentTimeMillis() & 0xfffffff);

1
index.d.ts vendored
View File

@@ -106,6 +106,7 @@ export interface DownloadOption {
metadata?: object;
isAllowedOverRoaming?: boolean;
isAllowedOverMetered?: boolean;
showNotification?: boolean;
}
export type Download = (options: DownloadOption) => DownloadTask;

View File

@@ -121,6 +121,7 @@ type DownloadOptions = {
metadata?: object,
isAllowedOverRoaming?: boolean,
isAllowedOverMetered?: boolean,
showNotification?: boolean;
}
export function download(options: DownloadOptions) {
@@ -137,6 +138,7 @@ export function download(options: DownloadOptions) {
if (options.isAllowedOverRoaming == null) options.isAllowedOverRoaming = true
if (options.isAllowedOverMetered == null) options.isAllowedOverMetered = true
if (options.showNotification == null) options.showNotification = false
const task = new DownloadTask({
id: options.id,