From 3b281a8c3f6fb90ae2089b1c152e9ab9f3c8fad2 Mon Sep 17 00:00:00 2001 From: Benjamin Gamard Date: Wed, 30 Jan 2019 16:53:07 +0100 Subject: [PATCH] Closes #270: add notification channel for android > 26 --- docs-android/app/build.gradle | 2 +- .../docs/service/FileUploadService.java | 23 +++++++++++++++---- .../gradle/wrapper/gradle-wrapper.properties | 4 ++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/docs-android/app/build.gradle b/docs-android/app/build.gradle index 25cfc4f4..a6238e78 100644 --- a/docs-android/app/build.gradle +++ b/docs-android/app/build.gradle @@ -4,7 +4,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:3.3.0' } } apply plugin: 'com.android.application' diff --git a/docs-android/app/src/main/java/com/sismics/docs/service/FileUploadService.java b/docs-android/app/src/main/java/com/sismics/docs/service/FileUploadService.java index 07fcb6cd..4a17325a 100644 --- a/docs-android/app/src/main/java/com/sismics/docs/service/FileUploadService.java +++ b/docs-android/app/src/main/java/com/sismics/docs/service/FileUploadService.java @@ -1,10 +1,12 @@ package com.sismics.docs.service; import android.app.IntentService; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.net.Uri; +import android.os.Build; import android.os.PowerManager; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat.Builder; @@ -29,7 +31,8 @@ import okhttp3.internal.Util; * @author bgamard */ public class FileUploadService extends IntentService { - private static final String TAG = "FileUploadService"; + private static final String TAG = "sismicsdocs:fileupload"; + private static final String CHANNEL_ID = "FileUploadService"; private static final int UPLOAD_NOTIFICATION_ID = 1; private static final int UPLOAD_NOTIFICATION_ID_DONE = 2; @@ -49,18 +52,30 @@ public class FileUploadService extends IntentService { super.onCreate(); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - notification = new NotificationCompat.Builder(this); + initChannels(); + notification = new NotificationCompat.Builder(this, CHANNEL_ID); PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); } + private void initChannels() { + if (Build.VERSION.SDK_INT < 26) { + return; + } + + NotificationChannel channel = new NotificationChannel(CHANNEL_ID, + "File Upload", NotificationManager.IMPORTANCE_HIGH); + channel.setDescription("Used to show file upload progress"); + notificationManager.createNotificationChannel(channel); + } + @Override protected void onHandleIntent(Intent intent) { if (intent == null) { return; } - wakeLock.acquire(); + wakeLock.acquire(60_000 * 30); // 30 minutes upload time maximum try { onStart(); handleFileUpload(intent.getStringExtra(PARAM_DOCUMENT_ID), (Uri) intent.getParcelableExtra(PARAM_URI)); @@ -77,7 +92,7 @@ public class FileUploadService extends IntentService { * * @param documentId Document ID * @param uri Data URI - * @throws IOException + * @throws IOException e */ private void handleFileUpload(final String documentId, final Uri uri) throws Exception { final InputStream is = getContentResolver().openInputStream(uri); diff --git a/docs-android/gradle/wrapper/gradle-wrapper.properties b/docs-android/gradle/wrapper/gradle-wrapper.properties index 84239c64..b0546596 100644 --- a/docs-android/gradle/wrapper/gradle-wrapper.properties +++ b/docs-android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Oct 18 22:37:49 CEST 2018 +#Wed Jan 30 16:31:31 CET 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip