From 7ec6e91cdc863a11fdccdcfbd2bf76567eda19e0 Mon Sep 17 00:00:00 2001 From: ThibaultBee Date: Thu, 14 Dec 2023 15:30:38 +0000 Subject: [PATCH] Bugfix/android workmanager api 34 --- README.md | 51 ++++++++++++++++++- examples/service/build.gradle | 10 ++-- examples/workmanager/build.gradle | 10 ++-- .../workmanager/src/main/AndroidManifest.xml | 10 ++++ .../api/work/workers/AbstractUploadWorker.kt | 15 +++++- src/main/res/values/strings.xml | 2 +- 6 files changed, 86 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8156c8e..c3a51c7 100644 --- a/README.md +++ b/README.md @@ -129,12 +129,59 @@ You have to add the following permissions in your `AndroidManifest.xml`: ```xml - - + + + + ``` Your application also has to dynamically request the `android.permission.READ_EXTERNAL_STORAGE` permission to upload videos. +### WorkManager + +To upload with the `WorkManager`, you also have to add the following lines in your `AndroidManifest.xml`: + +```xml + + + + + + + + ... + + + +``` + +### UploadService + + +To upload with the `UploadService`, you also have to add the following lines in your `AndroidManifest.xml`: + +```xml + + + + + + + + + +``` + + + ## Documentation ### API Endpoints diff --git a/examples/service/build.gradle b/examples/service/build.gradle index d69ab5e..62918f8 100644 --- a/examples/service/build.gradle +++ b/examples/service/build.gradle @@ -4,14 +4,16 @@ plugins { } android { - compileSdkVersion 33 - defaultConfig { applicationId "video.api.client.service.example" - minSdkVersion 21 - targetSdkVersion 33 + + minSdk 21 + targetSdk 34 + compileSdk 34 + versionCode 1 versionName "1.0" + multiDexEnabled true } diff --git a/examples/workmanager/build.gradle b/examples/workmanager/build.gradle index cc355f8..2c38ea0 100644 --- a/examples/workmanager/build.gradle +++ b/examples/workmanager/build.gradle @@ -4,14 +4,16 @@ plugins { } android { - compileSdkVersion 33 - defaultConfig { applicationId "video.api.client.work.example" - minSdkVersion 21 - targetSdkVersion 33 + + minSdk 21 + targetSdk 34 + compileSdk 34 + versionCode 1 versionName "1.0" + multiDexEnabled true } diff --git a/examples/workmanager/src/main/AndroidManifest.xml b/examples/workmanager/src/main/AndroidManifest.xml index 2fbc66b..80497d3 100644 --- a/examples/workmanager/src/main/AndroidManifest.xml +++ b/examples/workmanager/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ @@ -12,6 +13,9 @@ + + + + + + diff --git a/src/main/java/video/api/client/api/work/workers/AbstractUploadWorker.kt b/src/main/java/video/api/client/api/work/workers/AbstractUploadWorker.kt index b692f96..2409e95 100644 --- a/src/main/java/video/api/client/api/work/workers/AbstractUploadWorker.kt +++ b/src/main/java/video/api/client/api/work/workers/AbstractUploadWorker.kt @@ -3,6 +3,8 @@ package video.api.client.api.work.workers import android.annotation.SuppressLint import android.app.Notification import android.content.Context +import android.content.pm.ServiceInfo +import android.os.Build import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.work.* @@ -138,7 +140,18 @@ abstract class AbstractUploadWorker( } protected fun createForegroundInfo(notification: Notification): ForegroundInfo { - return ForegroundInfo(NotificationConfigurationStore.notificationId, notification) + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + ForegroundInfo( + NotificationConfigurationStore.notificationId, + notification, + ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC + ) + } else { + ForegroundInfo( + NotificationConfigurationStore.notificationId, + notification + ) + } } companion object { diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index bbb528b..935cc8d 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1,6 +1,6 @@ - api.video + Video uploader Uploading Uploaded %1d of %1d %1d %%