diff --git a/CHANGELOG.md b/CHANGELOG.md index 0627004a9..d204110bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Changed + +- target API 33 to prevent foreground service crashes with Android 14 beta 5 + ## [v1.9.2] - 2023-08-24 ### Changed diff --git a/android/app/build.gradle b/android/app/build.gradle index f34fb9948..b2ca6c651 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -83,7 +83,7 @@ android { // which implementation `DocumentBuilderImpl` is provided by the OS and is not customizable on Android, // but the implementation on API <19 is not robust enough and fails to build XMP documents minSdkVersion 19 - targetSdkVersion 34 + targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName manifestPlaceholders = [googleApiKey: keystoreProperties["googleApiKey"] ?: "", diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 06247d156..add648546 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -32,6 +32,11 @@ + + + + + diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/AnalysisWorker.kt b/android/app/src/main/kotlin/deckers/thibault/aves/AnalysisWorker.kt index 16e47dd16..9c0e7cbfb 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/AnalysisWorker.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/AnalysisWorker.kt @@ -3,6 +3,7 @@ package deckers.thibault.aves import android.app.PendingIntent import android.content.Context import android.content.Intent +import android.content.pm.ServiceInfo import android.os.Build import android.util.Log import androidx.core.app.NotificationChannelCompat @@ -148,16 +149,27 @@ class AnalysisWorker(context: Context, parameters: WorkerParameters) : Coroutine WorkManager.getInstance(applicationContext).createCancelPendingIntent(id) ).build() val icon = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) R.drawable.ic_notification else R.mipmap.ic_launcher_round + val contentTitle = title ?: applicationContext.getText(R.string.analysis_notification_default_title) val notification = NotificationCompat.Builder(applicationContext, NOTIFICATION_CHANNEL) - .setContentTitle(title ?: applicationContext.getText(R.string.analysis_notification_default_title)) + .setContentTitle(contentTitle) + .setTicker(contentTitle) .setContentText(message) - .setBadgeIconType(NotificationCompat.BADGE_ICON_NONE) .setSmallIcon(icon) + .setOngoing(true) .setContentIntent(openAppIntent) - .setPriority(NotificationCompat.PRIORITY_LOW) .addAction(stopAction) .build() - return ForegroundInfo(NOTIFICATION_ID, notification) + // TODO TLAD revisit with Android 14 >beta5 + return ForegroundInfo(NOTIFICATION_ID, notification); +// return if (Build.VERSION.SDK_INT >= 34) { +// // as of Android 14 beta 5, foreground service type is mandatory +// // despite the sample code omitting it at: +// // https://developer.android.com/guide/background/persistent/how-to/long-running +// val type = ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC +// ForegroundInfo(NOTIFICATION_ID, notification, type) +// } else { +// ForegroundInfo(NOTIFICATION_ID, notification) +// } } companion object {