diff --git a/.travis.yml b/.travis.yml index c88a0954..c715e9f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,10 +11,10 @@ android: - platform-tools # The BuildTools version used by your project - - build-tools-25.0.2 + - build-tools-26.0.1 # The SDK version used to compile your project - - android-25 + - android-26 # Additional components - extra-google-m2repository diff --git a/build.gradle b/build.gradle index 2a93cd9d..d831ee75 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,7 @@ buildscript { allprojects { repositories { jcenter() + maven { url 'http://maven.google.com' } mavenCentral() } } diff --git a/uploadservice-ftp/build.gradle b/uploadservice-ftp/build.gradle index 1c37b869..b61fe917 100644 --- a/uploadservice-ftp/build.gradle +++ b/uploadservice-ftp/build.gradle @@ -10,14 +10,14 @@ def projectGroup = "net.gotev" group = projectGroup version = "3.3" -def sdkVersion = 25; +def sdkVersion = 26; android { compileSdkVersion sdkVersion - buildToolsVersion '25.0.2' + buildToolsVersion '26.0.1' defaultConfig { - minSdkVersion 10 + minSdkVersion 14 targetSdkVersion sdkVersion versionCode 13 versionName version diff --git a/uploadservice-okhttp/build.gradle b/uploadservice-okhttp/build.gradle index fdfa8c7b..2a08a585 100644 --- a/uploadservice-okhttp/build.gradle +++ b/uploadservice-okhttp/build.gradle @@ -10,14 +10,14 @@ def projectGroup = "net.gotev" group = projectGroup version = "3.3" -def sdkVersion = 25; +def sdkVersion = 26; android { compileSdkVersion sdkVersion - buildToolsVersion '25.0.2' + buildToolsVersion '26.0.1' defaultConfig { - minSdkVersion 10 + minSdkVersion 14 targetSdkVersion sdkVersion versionCode 10 versionName version diff --git a/uploadservice/build.gradle b/uploadservice/build.gradle index 967a1077..855d44d6 100644 --- a/uploadservice/build.gradle +++ b/uploadservice/build.gradle @@ -10,14 +10,14 @@ def projectGroup = "net.gotev" group = projectGroup version = "3.3" -def sdkVersion = 25; +def sdkVersion = 26; android { compileSdkVersion sdkVersion - buildToolsVersion '25.0.2' + buildToolsVersion '26.0.1' defaultConfig { - minSdkVersion 10 + minSdkVersion 14 targetSdkVersion sdkVersion versionCode 26 versionName version @@ -33,7 +33,7 @@ android { } } -def supportLibraryVersion = "25.3.1" +def supportLibraryVersion = "26.0.0" dependencies { compile "com.android.support:appcompat-v7:${supportLibraryVersion}" diff --git a/uploadservice/src/main/java/net/gotev/uploadservice/UploadNotificationConfig.java b/uploadservice/src/main/java/net/gotev/uploadservice/UploadNotificationConfig.java index c2bc7925..c6e4b68b 100644 --- a/uploadservice/src/main/java/net/gotev/uploadservice/UploadNotificationConfig.java +++ b/uploadservice/src/main/java/net/gotev/uploadservice/UploadNotificationConfig.java @@ -4,6 +4,7 @@ import android.graphics.Bitmap; import android.os.Parcel; import android.os.Parcelable; +import android.support.annotation.NonNull; /** * Contains the configuration of the upload notification. @@ -14,6 +15,11 @@ public final class UploadNotificationConfig implements Parcelable { private boolean ringToneEnabled; + /** + * Notification channel ID + */ + private String notificationChannelId; + private UploadNotificationStatusConfig progress; private UploadNotificationStatusConfig completed; private UploadNotificationStatusConfig error; @@ -167,6 +173,17 @@ public final UploadNotificationConfig setRingToneEnabled(Boolean enabled) { return this; } + /** + * Sets notification channel ID + * + * @param channelId notification channel ID + * @return {@link UploadNotificationConfig} + */ + public final UploadNotificationConfig setNotificationChannelId(@NonNull String channelId){ + this.notificationChannelId = channelId; + return this; + } + public boolean isRingToneEnabled() { return ringToneEnabled; } @@ -187,6 +204,10 @@ public UploadNotificationStatusConfig getCancelled() { return cancelled; } + public String getNotificationChannelId(){ + return notificationChannelId; + } + @Override public int describeContents() { return 0; @@ -194,6 +215,7 @@ public int describeContents() { @Override public void writeToParcel(Parcel dest, int flags) { + dest.writeString(this.notificationChannelId); dest.writeByte(this.ringToneEnabled ? (byte) 1 : (byte) 0); dest.writeParcelable(this.progress, flags); dest.writeParcelable(this.completed, flags); @@ -202,6 +224,7 @@ public void writeToParcel(Parcel dest, int flags) { } protected UploadNotificationConfig(Parcel in) { + this.notificationChannelId = in.readString(); this.ringToneEnabled = in.readByte() != 0; this.progress = in.readParcelable(UploadNotificationStatusConfig.class.getClassLoader()); this.completed = in.readParcelable(UploadNotificationStatusConfig.class.getClassLoader()); diff --git a/uploadservice/src/main/java/net/gotev/uploadservice/UploadNotificationStatusConfig.java b/uploadservice/src/main/java/net/gotev/uploadservice/UploadNotificationStatusConfig.java index 1404bba0..d81d2bed 100644 --- a/uploadservice/src/main/java/net/gotev/uploadservice/UploadNotificationStatusConfig.java +++ b/uploadservice/src/main/java/net/gotev/uploadservice/UploadNotificationStatusConfig.java @@ -98,7 +98,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeTypedList(this.actions); } - public UploadNotificationStatusConfig() { + public UploadNotificationStatusConfig(){ } protected UploadNotificationStatusConfig(Parcel in) { diff --git a/uploadservice/src/main/java/net/gotev/uploadservice/UploadTask.java b/uploadservice/src/main/java/net/gotev/uploadservice/UploadTask.java index 97e57bac..b12034a4 100644 --- a/uploadservice/src/main/java/net/gotev/uploadservice/UploadTask.java +++ b/uploadservice/src/main/java/net/gotev/uploadservice/UploadTask.java @@ -1,10 +1,12 @@ package net.gotev.uploadservice; import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.media.RingtoneManager; +import android.os.Build; import android.os.Handler; import android.support.v4.app.NotificationCompat; @@ -115,6 +117,16 @@ public UploadTask() { */ protected void init(UploadService service, Intent intent) throws IOException { this.notificationManager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + String notificationChannelId = params.notificationConfig.getNotificationChannelId(); + if (notificationChannelId == null) { + notificationChannelId = UploadService.NAMESPACE; + } + if (notificationManager.getNotificationChannel(notificationChannelId) == null) { + NotificationChannel channel = new NotificationChannel(notificationChannelId, "Upload Service channel", NotificationManager.IMPORTANCE_DEFAULT); + notificationManager.createNotificationChannel(channel); + } + } this.service = service; this.mainThreadHandler = new Handler(service.getMainLooper()); this.params = intent.getParcelableExtra(UploadService.PARAM_TASK_PARAMETERS); @@ -430,7 +442,7 @@ private void createNotification(UploadInfo uploadInfo) { UploadNotificationStatusConfig statusConfig = params.notificationConfig.getProgress(); - NotificationCompat.Builder notification = new NotificationCompat.Builder(service) + NotificationCompat.Builder notification = new NotificationCompat.Builder(service, params.notificationConfig.getNotificationChannelId()) .setContentTitle(Placeholders.replace(statusConfig.title, uploadInfo)) .setContentText(Placeholders.replace(statusConfig.message, uploadInfo)) .setContentIntent(statusConfig.getClickIntent(service)) @@ -462,7 +474,7 @@ private void updateNotificationProgress(UploadInfo uploadInfo) { UploadNotificationStatusConfig statusConfig = params.notificationConfig.getProgress(); - NotificationCompat.Builder notification = new NotificationCompat.Builder(service) + NotificationCompat.Builder notification = new NotificationCompat.Builder(service, params.notificationConfig.getNotificationChannelId()) .setContentTitle(Placeholders.replace(statusConfig.title, uploadInfo)) .setContentText(Placeholders.replace(statusConfig.message, uploadInfo)) .setContentIntent(statusConfig.getClickIntent(service)) @@ -501,7 +513,7 @@ private void updateNotification(UploadInfo uploadInfo, UploadNotificationStatusC if (statusConfig.message == null) return; if (!statusConfig.autoClear) { - NotificationCompat.Builder notification = new NotificationCompat.Builder(service) + NotificationCompat.Builder notification = new NotificationCompat.Builder(service, params.notificationConfig.getNotificationChannelId()) .setContentTitle(Placeholders.replace(statusConfig.title, uploadInfo)) .setContentText(Placeholders.replace(statusConfig.message, uploadInfo)) .setContentIntent(statusConfig.getClickIntent(service))