Skip to content

Update to create a notification channel for SDK 26 and up #140

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

Closed
Closed
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
24 changes: 22 additions & 2 deletions src/background-http.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { ad } from "utils/utils";
import * as fileSystemModule from "file-system";
import * as common from "./index";

declare const android: any;

type Context = android.content.Context;
type ServerResponse = net.gotev.uploadservice.ServerResponse;
type UploadInfo = net.gotev.uploadservice.UploadInfo;
type UploadServiceBroadcastReceiver = net.gotev.uploadservice.UploadServiceBroadcastReceiver;
type UploadNotificationConfig = net.gotev.uploadservice.UploadNotificationConfig;

/* A snapshot-friendly, lazy-loaded class for ProgressReceiver BEGIN */
let ProgressReceiver: any;
Expand Down Expand Up @@ -186,8 +189,9 @@ class Task extends ObservableBase {

const displayNotificationProgress = typeof options.androidDisplayNotificationProgress === "boolean" ? options.androidDisplayNotificationProgress : true;
if (displayNotificationProgress) {
request.setNotificationConfig(new net.gotev.uploadservice.UploadNotificationConfig());
request.setNotificationConfig(Task.getUploadNotificationConfig(context));
}

const autoDeleteAfterUpload = typeof options.androidAutoDeleteAfterUpload === "boolean" ? options.androidAutoDeleteAfterUpload : false;
if (autoDeleteAfterUpload) {
request.setAutoDeleteFilesAfterSuccessfulUpload(true);
Expand Down Expand Up @@ -256,7 +260,7 @@ class Task extends ObservableBase {

const displayNotificationProgress = typeof options.androidDisplayNotificationProgress === "boolean" ? options.androidDisplayNotificationProgress : true;
if (displayNotificationProgress) {
request.setNotificationConfig(new net.gotev.uploadservice.UploadNotificationConfig());
request.setNotificationConfig(Task.getUploadNotificationConfig(context));
}

const headers = options.headers;
Expand Down Expand Up @@ -330,4 +334,20 @@ class Task extends ObservableBase {
cancel(): void {
(<any>net).gotev.uploadservice.UploadService.stopUpload(this._id);
}

private static getUploadNotificationConfig(context: Context): UploadNotificationConfig {

const uploadNotificationConfig = new net.gotev.uploadservice.UploadNotificationConfig();
if(android.os.Build.VERSION.SDK_INT >= 26){
const channel = new android.app.NotificationChannel(application.android.packageName,
application.android.packageName,
android.app.NotificationManager.IMPORTANCE_LOW);

const notificationManager = context.getSystemService(android.content.Context.NOTIFICATION_SERVICE)
notificationManager.createNotificationChannel(channel);

uploadNotificationConfig.setNotificationChannelId(application.android.packageName)
}
return uploadNotificationConfig;
}
}