mirror of
https://github.com/sismics/docs.git
synced 2024-11-16 11:17:57 +01:00
Closes #270: add notification channel for android > 26
This commit is contained in:
parent
fe40a0a677
commit
3b281a8c3f
@ -4,7 +4,7 @@ buildscript {
|
|||||||
google()
|
google()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
classpath 'com.android.tools.build:gradle:3.3.0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.sismics.docs.service;
|
package com.sismics.docs.service;
|
||||||
|
|
||||||
import android.app.IntentService;
|
import android.app.IntentService;
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.app.NotificationCompat.Builder;
|
import android.support.v4.app.NotificationCompat.Builder;
|
||||||
@ -29,7 +31,8 @@ import okhttp3.internal.Util;
|
|||||||
* @author bgamard
|
* @author bgamard
|
||||||
*/
|
*/
|
||||||
public class FileUploadService extends IntentService {
|
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 = 1;
|
||||||
private static final int UPLOAD_NOTIFICATION_ID_DONE = 2;
|
private static final int UPLOAD_NOTIFICATION_ID_DONE = 2;
|
||||||
@ -49,18 +52,30 @@ public class FileUploadService extends IntentService {
|
|||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
notification = new NotificationCompat.Builder(this);
|
initChannels();
|
||||||
|
notification = new NotificationCompat.Builder(this, CHANNEL_ID);
|
||||||
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
|
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
|
||||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
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
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
if (intent == null) {
|
if (intent == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wakeLock.acquire();
|
wakeLock.acquire(60_000 * 30); // 30 minutes upload time maximum
|
||||||
try {
|
try {
|
||||||
onStart();
|
onStart();
|
||||||
handleFileUpload(intent.getStringExtra(PARAM_DOCUMENT_ID), (Uri) intent.getParcelableExtra(PARAM_URI));
|
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 documentId Document ID
|
||||||
* @param uri Data URI
|
* @param uri Data URI
|
||||||
* @throws IOException
|
* @throws IOException e
|
||||||
*/
|
*/
|
||||||
private void handleFileUpload(final String documentId, final Uri uri) throws Exception {
|
private void handleFileUpload(final String documentId, final Uri uri) throws Exception {
|
||||||
final InputStream is = getContentResolver().openInputStream(uri);
|
final InputStream is = getContentResolver().openInputStream(uri);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#Thu Oct 18 22:37:49 CEST 2018
|
#Wed Jan 30 16:31:31 CET 2019
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user