Skip to content

Android Support Library + NotificationChannels #299

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 2, 2017
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ buildscript {
allprojects {
repositories {
jcenter()
maven { url 'http://maven.google.com' }
mavenCentral()
}
}
Expand Down
6 changes: 3 additions & 3 deletions uploadservice-ftp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions uploadservice-okhttp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions uploadservice/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +33,7 @@ android {
}
}

def supportLibraryVersion = "25.3.1"
def supportLibraryVersion = "26.0.0"

dependencies {
compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -187,13 +204,18 @@ public UploadNotificationStatusConfig getCancelled() {
return cancelled;
}

public String getNotificationChannelId(){
return notificationChannelId;
}

@Override
public int describeContents() {
return 0;
}

@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);
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeTypedList(this.actions);
}

public UploadNotificationStatusConfig() {
public UploadNotificationStatusConfig(){
}

protected UploadNotificationStatusConfig(Parcel in) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down