Skip to content

Commit f2254d4

Browse files
authored
feat: Android API 33 support (#639)
* feat: updated all dependencies, gradle and bumped target SDK to 33 * feat: updated library manifest to include POST_NOTIFICATIONS permission and demo app to request notifications permissions on demand on android API 33+ * ci: bump java to 17 and API to 33 * readme: update for android 13 * feat: updated SimpleMultipartUpload demo app
1 parent 1f07a5a commit f2254d4

File tree

30 files changed

+123
-67
lines changed

30 files changed

+123
-67
lines changed

.github/workflows/android.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: run tests
1919
uses: reactivecircus/android-emulator-runner@v2
2020
with:
21-
api-level: 31
21+
api-level: 33
2222
script: ./gradlew connectedCheck
2323

2424
unit-test-and-build:
@@ -29,7 +29,7 @@ jobs:
2929
- name: set up JDK
3030
uses: actions/setup-java@v1
3131
with:
32-
java-version: 11
32+
java-version: 17
3333
- name: Unit Test
3434
run: ./gradlew testDebugUnitTest
3535
- name: Android Test Report
@@ -46,6 +46,6 @@ jobs:
4646
- name: set up JDK
4747
uses: actions/setup-java@v1
4848
with:
49-
java-version: 11
49+
java-version: 17
5050
- name: Build with Gradle
5151
run: cd examples/app && ./gradlew clean assembleDebug

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ You are also safe if your app is put in the background. All the uploads will con
2929
Bear in mind that if you kill your app, the service gets killed as well, as it's attached to your app's process and all the currently running uploads will be terminated abruptly.
3030

3131
## Features <a name="features"></a>
32-
* Android 5.0 (API 21) to Android 12 (API 31) support.
32+
* Android 5.0 (API 21) to Android 13 (API 33) support.
33+
* *Android 13 Note, for apps targeting API 33 or newer*:
34+
* Due to new behavior changes, you are [required to request POST_NOTIFICATIONS permission at runtime in your app](https://developer.android.com/develop/ui/views/notifications/notification-permission) or else the upload progress won't be shown. To see an example, please look at the BaseActivity in the `examples/app` folder.
3335
* *Android 12 Note, for apps targeting API 31 or newer*:
3436
* What's supported: uploads initiated while the app is in foreground, with progress indication notification
3537
* What's NOT supported: uploads started while the app is in the background or uploads without progress indication notification. This is due to the Service limitations imposed by Google, which requires all background services to display a notification to the user. Current architecture cannot support this. For support of those use-cases, WorkManager is the only option.

examples/SimpleMultipartUpload/app/build.gradle

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,42 @@ apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33

44
android {
5-
compileSdkVersion 30
5+
namespace "it.gotev.testapp"
6+
compileSdkVersion target_sdk
7+
68
defaultConfig {
79
applicationId "it.gotev.testapp"
810
minSdkVersion 21
9-
targetSdkVersion 30
10-
versionCode 2
11-
versionName "1.1"
11+
targetSdkVersion target_sdk
12+
versionCode 3
13+
versionName "1.3"
1214
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1315
}
16+
1417
buildTypes {
1518
release {
1619
minifyEnabled false
1720
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
1821
}
1922
}
23+
24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_17
26+
targetCompatibility JavaVersion.VERSION_17
27+
}
2028
}
2129

2230
dependencies {
2331
implementation fileTree(dir: 'libs', include: ['*.jar'])
2432
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
25-
implementation 'androidx.appcompat:appcompat:1.3.0'
26-
implementation 'androidx.core:core-ktx:1.5.0'
27-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
28-
testImplementation 'junit:junit:4.13'
29-
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
30-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
33+
implementation 'androidx.appcompat:appcompat:1.6.1'
34+
implementation 'androidx.core:core-ktx:1.10.1'
35+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
36+
testImplementation 'junit:junit:4.13.2'
37+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
38+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
3139

32-
def uploadServiceVersion = "4.5.5"
40+
def uploadServiceVersion = "4.7.0"
3341

3442
implementation "net.gotev:uploadservice:$uploadServiceVersion"
3543
}

examples/SimpleMultipartUpload/app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="it.gotev.testapp">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
45

56
<application
67
android:allowBackup="true"
@@ -10,7 +11,8 @@
1011
android:roundIcon="@mipmap/ic_launcher_round"
1112
android:supportsRtl="true"
1213
android:theme="@style/AppTheme">
13-
<activity android:name=".MainActivity">
14+
<activity android:name=".MainActivity"
15+
android:exported="true">
1416
<intent-filter>
1517
<action android:name="android.intent.action.MAIN" />
1618

examples/SimpleMultipartUpload/app/src/main/java/it/gotev/testapp/MainActivity.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package it.gotev.testapp
22

3+
import android.Manifest
34
import android.app.Activity
45
import android.content.Intent
6+
import android.content.pm.PackageManager
7+
import android.os.Build
58
import android.os.Bundle
69
import android.widget.Button
10+
import androidx.activity.result.contract.ActivityResultContracts
711
import androidx.appcompat.app.AppCompatActivity
12+
import androidx.core.content.ContextCompat
813
import net.gotev.uploadservice.protocols.multipart.MultipartUploadRequest
914

1015
class MainActivity : AppCompatActivity() {
@@ -15,9 +20,20 @@ class MainActivity : AppCompatActivity() {
1520
const val pickFileRequestCode = 42
1621
}
1722

23+
private val notificationPermissionRequest = registerForActivityResult(ActivityResultContracts.RequestPermission()) {
24+
// custom logic when the user either allows or disallows notifications
25+
}
26+
27+
private fun checkPostNotificationsPermission() {
28+
if (Build.VERSION.SDK_INT >= 33 && ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
29+
notificationPermissionRequest.launch(Manifest.permission.POST_NOTIFICATIONS)
30+
}
31+
}
32+
1833
override fun onCreate(savedInstanceState: Bundle?) {
1934
super.onCreate(savedInstanceState)
2035
setContentView(R.layout.activity_main)
36+
checkPostNotificationsPermission()
2137

2238
findViewById<Button>(R.id.uploadButton).setOnClickListener {
2339
pickFile()

examples/SimpleMultipartUpload/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.4.32'
4+
ext.gradle_version = '8.0.2'
5+
ext.kotlin_version = '1.8.20'
6+
ext.target_sdk = 33
7+
58
repositories {
69
google()
710
mavenCentral()
11+
maven {
12+
url "https://plugins.gradle.org/m2/"
13+
}
814
}
15+
916
dependencies {
10-
classpath 'com.android.tools.build:gradle:4.1.3'
17+
classpath "com.android.tools.build:gradle:$gradle_version"
1118
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1219
// NOTE: Do not place your application dependencies here; they belong
1320
// in the individual module build.gradle files

examples/SimpleMultipartUpload/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip

examples/app/.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/app/demoapp/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33

44
android {
5+
namespace "net.gotev.uploadservicedemo"
56
compileSdkVersion target_sdk
67

78
defaultConfig {
@@ -31,8 +32,8 @@ android {
3132
}
3233

3334
compileOptions {
34-
sourceCompatibility JavaVersion.VERSION_1_8
35-
targetCompatibility JavaVersion.VERSION_1_8
35+
sourceCompatibility JavaVersion.VERSION_17
36+
targetCompatibility JavaVersion.VERSION_17
3637
}
3738
}
3839

examples/app/demoapp/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip

examples/app/demoapp/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="net.gotev.uploadservicedemo">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
43

54
<application
65
android:name=".App"

examples/app/demoapp/src/main/java/net/gotev/uploadservicedemo/activities/BaseActivity.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package net.gotev.uploadservicedemo.activities
22

3+
import android.Manifest
34
import android.app.PendingIntent
45
import android.content.Intent
6+
import android.content.pm.PackageManager
57
import android.graphics.Bitmap
68
import android.graphics.Color
79
import android.os.Build
10+
import android.os.Bundle
11+
import androidx.activity.result.contract.ActivityResultContracts
812
import androidx.annotation.StringRes
913
import androidx.appcompat.app.AppCompatActivity
14+
import androidx.core.content.ContextCompat
1015
import net.gotev.uploadservice.data.UploadNotificationAction
1116
import net.gotev.uploadservice.data.UploadNotificationConfig
1217
import net.gotev.uploadservice.data.UploadNotificationStatusConfig
@@ -19,6 +24,22 @@ import net.gotev.uploadservicedemo.extensions.inputMethodManager
1924
import java.util.ArrayList
2025

2126
open class BaseActivity : AppCompatActivity() {
27+
28+
private val notificationPermissionRequest = registerForActivityResult(ActivityResultContracts.RequestPermission()) {
29+
// custom logic when the user either allows or disallows notifications
30+
}
31+
32+
private fun checkPostNotificationsPermission() {
33+
if (Build.VERSION.SDK_INT >= 33 && ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
34+
notificationPermissionRequest.launch(Manifest.permission.POST_NOTIFICATIONS)
35+
}
36+
}
37+
38+
override fun onCreate(savedInstanceState: Bundle?) {
39+
super.onCreate(savedInstanceState)
40+
checkPostNotificationsPermission()
41+
}
42+
2243
override fun onPause() {
2344
super.onPause()
2445

examples/app/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
# org.gradle.parallel=true
1919
android.enableJetifier=true
2020
android.useAndroidX=true
21+
android.defaults.buildfeatures.buildconfig=true
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Aug 21 13:17:15 CEST 2020
1+
#Sun Jul 09 10:09:56 CEST 2023
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
org.gradle.parallel=true
1919
org.gradle.caching=true
2020
android.useAndroidX=true
21+
android.defaults.buildfeatures.buildconfig=true

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip

manifest.gradle

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@ ext {
99
library_licenses = ["Apache-2.0"]
1010
library_licenses_url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
1111
library_project_group = 'net.gotev'
12-
library_version = '4.7.0'
13-
version_code = 48
12+
library_version = '4.8.0'
13+
version_code = 49
1414
min_sdk = 21
15-
target_sdk = 31
15+
target_sdk = 33
1616
demo_app_id = 'net.gotev.uploadservicedemo'
1717

1818
// Gradle classpath dependencies versions
19-
kotlin_version = '1.4.32'
20-
gradle_version = '7.0.3'
19+
kotlin_version = '1.8.20'
20+
gradle_version = '8.0.2'
2121
kotlin_lint_version = '9.0.0'
2222

2323
// Library and app testing dependencies versions
24-
junit_version = '4.13'
25-
androidx_test_core_version = '1.3.0'
26-
androidx_test_runner_version = '1.3.0'
27-
androidx_test_rules_version = '1.3.0'
28-
androidx_test_ext_junit_version = '1.1.2'
29-
androidx_test_ext_truth_version = '1.3.0'
24+
junit_version = '4.13.2'
25+
androidx_test_core_version = '1.5.0'
26+
androidx_test_runner_version = '1.5.2'
27+
androidx_test_rules_version = '1.5.0'
28+
androidx_test_ext_junit_version = '1.1.5'
29+
androidx_test_ext_truth_version = '1.5.0'
3030
truth_version = '1.0.1'
31-
androidx_test_espresso_version = '3.3.0'
31+
androidx_test_espresso_version = '3.5.1'
3232
mock_web_server_version = '4.9.0'
3333

3434
// Library and app dependencies versions
35-
androidx_lifecycle_version = '2.3.1'
36-
androidx_appcompat_version = '1.3.0'
35+
androidx_lifecycle_version = '2.6.1'
36+
androidx_appcompat_version = '1.6.1'
3737
}

uploadservice-ftp/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ group = library_project_group
2020
version = library_version
2121

2222
android {
23+
namespace "net.gotev.uploadservice.ftp"
2324
compileSdkVersion target_sdk
2425

2526
defaultConfig {
@@ -38,8 +39,8 @@ android {
3839
}
3940

4041
compileOptions {
41-
sourceCompatibility JavaVersion.VERSION_1_8
42-
targetCompatibility JavaVersion.VERSION_1_8
42+
sourceCompatibility JavaVersion.VERSION_17
43+
targetCompatibility JavaVersion.VERSION_17
4344
}
4445

4546
lintOptions {

uploadservice-ftp/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip

uploadservice-ftp/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<manifest package="net.gotev.uploadservice.ftp">
1+
<manifest>
22

33
<application></application>
44

uploadservice-okhttp/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ group = library_project_group
2020
version = library_version
2121

2222
android {
23+
namespace "net.gotev.uploadservice.okhttp"
2324
compileSdkVersion target_sdk
2425

2526
defaultConfig {
@@ -38,8 +39,8 @@ android {
3839
}
3940

4041
compileOptions {
41-
sourceCompatibility JavaVersion.VERSION_1_8
42-
targetCompatibility JavaVersion.VERSION_1_8
42+
sourceCompatibility JavaVersion.VERSION_17
43+
targetCompatibility JavaVersion.VERSION_17
4344
}
4445

4546
lintOptions {

uploadservice-okhttp/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<manifest package="net.gotev.uploadservice.okhttp">
1+
<manifest>
22

33
<application></application>
44

0 commit comments

Comments
 (0)