Skip to content

Commit

Permalink
Merge pull request #86 from apivideo/bugfix/android_workmanager_api_34
Browse files Browse the repository at this point in the history
Bugfix/android workmanager api 34
  • Loading branch information
bot-api-video committed Dec 15, 2023
2 parents ade7243 + 0ca8c53 commit f2912ed
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 33 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All changes to this project will be documented in this file.

## [1.3.3] - 2023-12-14
- Add support for API level >= 34 for WorkManager

## [1.3.2] - 2023-09-26
- Extend Android minSdkVersion to 21

Expand Down
57 changes: 52 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>video.api</groupId>
<artifactId>android-video-uploader</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
<scope>compile</scope>
</dependency>
```
Expand All @@ -72,7 +72,7 @@ Add this dependency to your project's POM:
Add this dependency to your project's build file:

```groovy
implementation "video.api:android-video-uploader:1.3.2"
implementation "video.api:android-video-uploader:1.3.3"
```

#### Others
Expand All @@ -85,7 +85,7 @@ mvn clean package

Then manually install the following JARs:

* `target/android-video-uploader-1.3.2.jar`
* `target/android-video-uploader-1.3.3.jar`
* `target/lib/*.jar`

### Code sample
Expand Down Expand Up @@ -121,12 +121,59 @@ You have to add the following permissions in your `AndroidManifest.xml`:

```xml
<uses-permission android:name="android.permission.INTERNET" />
<!-- Application requires android.permission.READ_EXTERNAL_STORAGE to upload videos` -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!-- The application requires READ_EXTERNAL_STORAGE or READ_MEDIA_VIDEO to access video to upload them` -->
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
```

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
<!-- The application requires POST_NOTIFICATIONS to display the upload notification -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<!-- The application requires FOREGROUND_SERVICE_DATA_SYNC for API >= 34 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application>
...
<!-- The application requires to declare a service type for API >= 34 -->
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
tools:node="merge" />
</application>
```

### UploadService


To upload with the `UploadService`, you also have to add the following lines in your `AndroidManifest.xml`:

```xml
<!-- The application requires POST_NOTIFICATIONS to display the upload notification -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application>
<!--
The application requires to declare your service, replace `YourUploaderService` by the package
of your service or by the package of `UploadService` if you directly use `UploadService`.
-->
<service android:name=".YourUploaderService" />
</application>
```



## Documentation

### API Endpoints
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'maven-publish'
apply plugin: 'kotlin-android'

group = 'video.api'
version = '1.3.2'
version = '1.3.3'

buildscript {
repositories {
Expand Down
7 changes: 4 additions & 3 deletions examples/service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ plugins {
}

android {
compileSdk 33

defaultConfig {
applicationId "video.api.uploader.service.example"

minSdk 21
targetSdk 33
targetSdk 34
compileSdk 34

versionCode 1
versionName "1.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,6 @@ class MainActivity : AppCompatActivity(), UploadServiceListener {
UploadService.unbindService(this, serviceConnection)
}

private val requestPermissionLauncher =
registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (isGranted) {
launchFilePickerIntent()
} else {
this.showDialog(
getString(R.string.permission),
getString(R.string.permission_required)
)
}
}

private var filesPickerResult =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == RESULT_OK) {
Expand Down
10 changes: 6 additions & 4 deletions examples/workmanager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ plugins {
}

android {
compileSdkVersion 33

defaultConfig {
applicationId "video.api.uploader.work.example"
minSdkVersion 21
targetSdkVersion 33

minSdk 21
targetSdk 34
compileSdk 34

versionCode 1
versionName "1.0"

multiDexEnabled true
}

Expand Down
10 changes: 10 additions & 0 deletions examples/workmanager/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="video.api.uploader.work.example">

<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -12,6 +13,9 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<!-- When targeting API >= 34 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_api_video"
Expand All @@ -29,6 +33,12 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- When targeting API >= 34 -->
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
tools:node="merge" />
</application>

</manifest>
4 changes: 2 additions & 2 deletions maven-push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ apply plugin: 'maven-publish'
apply plugin: 'signing'

def isReleaseBuild() {
return !"1.3.2".contains("SNAPSHOT")
return !"1.3.3".contains("SNAPSHOT")
}

def getReleaseRepositoryUrl() {
Expand Down Expand Up @@ -47,7 +47,7 @@ afterEvaluate { project ->

groupId = "video.api"
artifactId = "android-video-uploader"
version = "1.3.2"
version = "1.3.3"

pom {
name = "video.api:android-video-uploader"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>android-video-uploader</artifactId>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<version>1.3.2</version>
<version>1.3.3</version>
<url>https://github.com/apivideo/api.video-android-uploader</url>
<description>The official Android api.video uploader</description>
<scm>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/video/api/uploader/api/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private OkHttpClient initHttpClient(List<Interceptor> interceptors) {
private void init() {
verifyingSsl = true;
json = new JSON();
addDefaultHeader("AV-Origin-Client", "android-uploader:1.3.2");
addDefaultHeader("AV-Origin-Client", "android-uploader:1.3.3");
}

private boolean isValid(String regex, String field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package video.api.uploader.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.*
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="upload_notification_channel_name">api.video</string>
<string name="upload_notification_channel_name">Video uploader</string>
<string name="upload_notification_progress_title">Uploading</string>
<string name="upload_notification_progress_text">Uploaded %1d of %1d</string>
<string name="upload_notification_current_progress_text">%1d %%</string>
Expand Down

0 comments on commit f2912ed

Please sign in to comment.