Skip to content

Commit 5824349

Browse files
mukaschultzeVladimir Amiorkov
authored andcommitted
feat(android): add options to set notifications channel id, ringtone enabled and auto clear (#239)
* androidAutoClearNotification implemented * androidRingToneEnabled implemented * androidNotificationChannelID implemented * better way of using default values * add android notes on readme
1 parent 5a588b5 commit 5824349

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ androidDisplayNotificationProgress | `boolean` | (Android only) Used to set if p
7676
androidNotificationTitle | `string` | (Android only) Used to set the title shown in the Android notifications center.
7777
androidAutoDeleteAfterUpload | `boolean` | (Android only) Used to set if files should be deleted automatically after upload.
7878
androidMaxRetries | `number` | (Android only) Used to set the maximum retry count. The default retry count is 0. https://github.com/gotev/android-upload-service/wiki/Recipes#backoff
79+
androidAutoClearNotification | `boolean` | (Android only) Used to set if notifications should be cleared automatically upon upload completion. Default is false. Please note that setting this to true will also disable the ringtones.
80+
androidRingToneEnabled | `boolean` | (Android only) Used to set if a ringtone should be played upon upload completion. Default is true. Please note that this flag has no effect when `androidAutoClearNotification` is set to true.
81+
androidNotificationChannelID | `string` | (Android only) Used to set the channel ID for the notifications.
7982

8083
The task object has the following properties and methods, that can be used to get information about the upload:
8184

src/background-http.android.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,23 @@ function setRequestOptions(request: any, options: common.Request) {
307307
if (displayNotificationProgress) {
308308
const uploadNotificationConfig = new net.gotev.uploadservice.UploadNotificationConfig();
309309
const notificationTitle = typeof options.androidNotificationTitle === "string" ? options.androidNotificationTitle : 'File Upload';
310+
310311
uploadNotificationConfig.setTitleForAllStatuses(notificationTitle);
312+
313+
if (typeof options.androidRingToneEnabled === "boolean") {
314+
uploadNotificationConfig.setRingToneEnabled(new java.lang.Boolean(options.androidRingToneEnabled));
315+
}
316+
317+
if (typeof options.androidAutoClearNotification === "boolean") {
318+
uploadNotificationConfig.getCompleted().autoClear = options.androidAutoClearNotification;
319+
uploadNotificationConfig.getCancelled().autoClear = options.androidAutoClearNotification;
320+
uploadNotificationConfig.getError().autoClear = options.androidAutoClearNotification;
321+
}
322+
323+
if (typeof options.androidNotificationChannelID === "string" && options.androidNotificationChannelID) {
324+
uploadNotificationConfig.setNotificationChannelId(options.androidNotificationChannelID);
325+
}
326+
311327
request.setNotificationConfig(uploadNotificationConfig);
312328
}
313329
const autoDeleteAfterUpload = typeof options.androidAutoDeleteAfterUpload === "boolean" ? options.androidAutoDeleteAfterUpload : false;

src/index.d.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ export interface Task {
8585
* Cancel the Upload Task.
8686
*/
8787
cancel(): void;
88-
/**
89-
* Subscribe for a general event.
90-
* @param event The name of the event to subscribe for.
91-
* @param handler The handler called when the event occure.
92-
* @event
93-
*/
88+
/**
89+
* Subscribe for a general event.
90+
* @param event The name of the event to subscribe for.
91+
* @param handler The handler called when the event occure.
92+
* @event
93+
*/
9494
on(event: string, handler: (e: observable.EventData) => void): void;
9595

9696
/**
@@ -194,4 +194,19 @@ export interface Request {
194194
* https://github.com/gotev/android-upload-service/wiki/Recipes#backoff
195195
*/
196196
androidMaxRetries?: number;
197+
198+
/*
199+
* Use this to set if notifications should be cleared automatically upon upload completion
200+
*/
201+
androidAutoClearNotification?: boolean;
202+
203+
/*
204+
* Use this to set if a ringtone should be played upon upload completion
205+
*/
206+
androidRingToneEnabled?: boolean;
207+
208+
/*
209+
* Use this to set the channel ID for the notifications
210+
*/
211+
androidNotificationChannelID?: string;
197212
}

0 commit comments

Comments
 (0)