mirror of
https://github.com/zoriya/react-native-background-downloader.git
synced 2025-12-06 06:56:10 +00:00
Add showNotification option on android
This commit is contained in:
@@ -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**
|
||||
|
||||
|
||||
@@ -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
1
index.d.ts
vendored
@@ -106,6 +106,7 @@ export interface DownloadOption {
|
||||
metadata?: object;
|
||||
isAllowedOverRoaming?: boolean;
|
||||
isAllowedOverMetered?: boolean;
|
||||
showNotification?: boolean;
|
||||
}
|
||||
|
||||
export type Download = (options: DownloadOption) => DownloadTask;
|
||||
|
||||
2
index.ts
2
index.ts
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user