Skip to content

feat(android): add options to set notifications channel id, ringtone enabled and auto clear #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ androidDisplayNotificationProgress | `boolean` | (Android only) Used to set if p
androidNotificationTitle | `string` | (Android only) Used to set the title shown in the Android notifications center.
androidAutoDeleteAfterUpload | `boolean` | (Android only) Used to set if files should be deleted automatically after upload.
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
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.
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.
androidNotificationChannelID | `string` | (Android only) Used to set the channel ID for the notifications.

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

Expand Down
16 changes: 16 additions & 0 deletions src/background-http.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,23 @@ function setRequestOptions(request: any, options: common.Request) {
if (displayNotificationProgress) {
const uploadNotificationConfig = new net.gotev.uploadservice.UploadNotificationConfig();
const notificationTitle = typeof options.androidNotificationTitle === "string" ? options.androidNotificationTitle : 'File Upload';

uploadNotificationConfig.setTitleForAllStatuses(notificationTitle);

if (typeof options.androidRingToneEnabled === "boolean") {
uploadNotificationConfig.setRingToneEnabled(new java.lang.Boolean(options.androidRingToneEnabled));
}

if (typeof options.androidAutoClearNotification === "boolean") {
uploadNotificationConfig.getCompleted().autoClear = options.androidAutoClearNotification;
uploadNotificationConfig.getCancelled().autoClear = options.androidAutoClearNotification;
uploadNotificationConfig.getError().autoClear = options.androidAutoClearNotification;
}

if (typeof options.androidNotificationChannelID === "string" && options.androidNotificationChannelID) {
uploadNotificationConfig.setNotificationChannelId(options.androidNotificationChannelID);
}

request.setNotificationConfig(uploadNotificationConfig);
}
const autoDeleteAfterUpload = typeof options.androidAutoDeleteAfterUpload === "boolean" ? options.androidAutoDeleteAfterUpload : false;
Expand Down
27 changes: 21 additions & 6 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ export interface Task {
* Cancel the Upload Task.
*/
cancel(): void;
/**
* Subscribe for a general event.
* @param event The name of the event to subscribe for.
* @param handler The handler called when the event occure.
* @event
*/
/**
* Subscribe for a general event.
* @param event The name of the event to subscribe for.
* @param handler The handler called when the event occure.
* @event
*/
on(event: string, handler: (e: observable.EventData) => void): void;

/**
Expand Down Expand Up @@ -194,4 +194,19 @@ export interface Request {
* https://github.com/gotev/android-upload-service/wiki/Recipes#backoff
*/
androidMaxRetries?: number;

/*
* Use this to set if notifications should be cleared automatically upon upload completion
*/
androidAutoClearNotification?: boolean;

/*
* Use this to set if a ringtone should be played upon upload completion
*/
androidRingToneEnabled?: boolean;

/*
* Use this to set the channel ID for the notifications
*/
androidNotificationChannelID?: string;
}