Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget worker fix #140

Merged
merged 8 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ Supported features:

* Gradle 7.6
* JDK 11
* Android SDK 34
* Android SDK 22
rsedykh marked this conversation as resolved.
Show resolved Hide resolved

11 changes: 11 additions & 0 deletions documentation/WIDGET.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
</resources>
```

#### If your app targets Android 14 (API level 34) or higher you must specify a foreground service type for all long-running workers.
rsedykh marked this conversation as resolved.
Show resolved Hide resolved

Declare your worker's foreground service type with `dataSync` foreground service type in your app's manifest to support our worker:

```xml
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync|your_type"
tools:node="replace" />
```

##### Select and upload file to Uploadcare from any available social network/camera/local file from Activity/Fragment.

Kotlin
Expand Down
5 changes: 0 additions & 5 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<provider
android:authorities="${applicationId}.androidx-startup"
android:name="androidx.startup.InitializationProvider"
tools:node="remove"/>
</application>

</manifest>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project-wide Gradle settings.
version=4.3.1
version=4.3.2

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
appVersion = "4.3.1"
appVersion = "4.3.2"
kotlinVersion = "1.9.23"
kotlinCoroutines = "1.8.0"
minSdk = "22"
Expand Down
2 changes: 1 addition & 1 deletion library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ The latest stable version is available at Maven Central.
To include it in your Android project, add this line to the 'gradle.build' file:

```
implementation 'com.uploadcare.android.library:uploadcare-android:4.3.1'
implementation 'com.uploadcare.android.library:uploadcare-android:4.3.2'
```
2 changes: 1 addition & 1 deletion widget/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ The latest stable version is available at Maven Central.
To include it in your Android project, add this line to the 'gradle.build' file:

```
implementation 'com.uploadcare.android.widget:uploadcare-android-widget:4.3.1'
implementation 'com.uploadcare.android.widget:uploadcare-android-widget:4.3.2'
```
16 changes: 8 additions & 8 deletions widget/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application
android:allowBackup="true"
Expand All @@ -24,15 +25,14 @@
</provider>

<provider
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
tools:node="remove"
tools:ignore="ExportedContentProvider" />

<provider
android:name=".worker.UploadcareWorkManagerInitializer"
android:authorities="${applicationId}.UploadcareWorkManagerInitializer"
android:name=".worker.UploadcareWidgetInitializer"
android:authorities="${applicationId}.UploadcareWidgetInitializer"
android:exported="false" />

<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
tools:node="merge" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.uploadcare.android.widget.worker
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
Expand Down Expand Up @@ -99,7 +100,15 @@ class FileUploadWorker(appContext: Context,
private fun createForegroundInfo(notificationBuilder: NotificationCompat.Builder)
: ForegroundInfo {
//Notification ID
return ForegroundInfo(NOTIFICATION_ID, notificationBuilder.build())
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ForegroundInfo(
NOTIFICATION_ID,
notificationBuilder.build(),
FOREGROUND_SERVICE_TYPE_DATA_SYNC
)
} else {
ForegroundInfo(NOTIFICATION_ID, notificationBuilder.build())
}
}

private fun updateNotificationProgress(content: String, progress: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import android.content.pm.ProviderInfo
import android.database.Cursor
import android.net.Uri
import androidx.annotation.RestrictTo
import androidx.work.Configuration
import androidx.work.WorkManager
import com.uploadcare.android.widget.controller.UploadcareWidget

/**
Expand All @@ -18,18 +16,11 @@ import com.uploadcare.android.widget.controller.UploadcareWidget
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
class UploadcareWorkManagerInitializer : ContentProvider() {
class UploadcareWidgetInitializer : ContentProvider() {

override fun onCreate(): Boolean {
//Initialize UploadcareWidget.
UploadcareWidget.init(context!!)
// provide custom configuration
val workManagerConfig = Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.INFO)
.build()

// initialize WorkManager
WorkManager.initialize(context!!, workManagerConfig)

return true
}
Expand Down
Loading