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

0 commit comments

Comments
 (0)