diff --git a/packages/flutter_background_service/README.md b/packages/flutter_background_service/README.md index 377d7889..4c42b272 100644 --- a/packages/flutter_background_service/README.md +++ b/packages/flutter_background_service/README.md @@ -11,28 +11,15 @@ A flutter plugin for execute dart code in background. > **WARNING**: > > Please make sure your project already use the version of gradle tools below: -> - in android/build.gradle ```classpath 'com.android.tools.build:gradle:7.1.2'``` -> - in android/gradle/wrapper/gradle-wrapper.properties ```distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip``` +> - in android/build.gradle ```classpath 'com.android.tools.build:gradle:7.4.2'``` +> - in android/build.gradle ```ext.kotlin_version = '1.8.10'``` +> - in android/gradle/wrapper/gradle-wrapper.properties ```distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip``` ### Configuration required for Foreground Services on Android 14 (SDK 34) Applications that target SDK 34 and use foreground services need to include some additional configuration to declare the type of foreground service they use: * Determine the type of foreground service your app requires by consulting [the documentation](https://developer.android.com/about/versions/14/changes/fgs-types-required) -* Update your `android/app/build.gradle` file to set the manifest placeholder to the value to use for `android:foregroundServiceType`: - -```gradle -android { - ... - - defaultConfig { - ... - // Replace this with the value to use for android:foregroundServiceType - // eg 'camera', 'connectedDevice', 'location', etc - manifestPlaceholders['foregroundServiceType'] = '...' - } -} -``` * Add the corresponding permission to your `android/app/src/main/AndroidManifest.xml` file: @@ -45,11 +32,33 @@ android { Eg, if you picked 'location', use 'android.permission.FOREGROUND_SERVICE_LOCATION' --> + + + + + + + + + ... ... + ``` -* Consult the documentation to determine if there are runtime permissions you need to request before you can start the service +> **WARNING**: +> * YOU MUST MAKE SURE ANY REQUIRED PERMISSIONS TO BE GRANTED BEFORE YOU START THE SERVICE + ### Using custom notification for Foreground Service You can make your own custom notification for foreground service. It can give you more power to make notifications more attractive to users, for example adding progressbars, buttons, actions, etc. The example below is using [flutter_local_notifications](https://pub.dev/packages/flutter_local_notifications) plugin, but you can use any other notification plugin. You can follow how to make it below: diff --git a/packages/flutter_background_service/example/android/app/build.gradle b/packages/flutter_background_service/example/android/app/build.gradle index 5ae9db09..f4df65b1 100644 --- a/packages/flutter_background_service/example/android/app/build.gradle +++ b/packages/flutter_background_service/example/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 33 + compileSdkVersion 34 // compileOptions { // sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/packages/flutter_background_service/example/android/app/src/main/AndroidManifest.xml b/packages/flutter_background_service/example/android/app/src/main/AndroidManifest.xml index e60bce76..8ed136b4 100644 --- a/packages/flutter_background_service/example/android/app/src/main/AndroidManifest.xml +++ b/packages/flutter_background_service/example/android/app/src/main/AndroidManifest.xml @@ -1,9 +1,19 @@ + + + + + + + = Build.VERSION_CODES.S) { + if (SDK_INT >= Build.VERSION_CODES.S) { flags |= PendingIntent.FLAG_MUTABLE; } @@ -169,7 +169,7 @@ protected void updateNotificationInfo() { .setContentIntent(pi); try { - ServiceCompat.startForeground(this, notificationId, mBuilder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST); + ServiceCompat.startForeground(this, notificationId, mBuilder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST); } catch (SecurityException e) { Log.w(TAG, "Failed to start foreground service due to SecurityException - have you forgotten to request a permission? - " + e.getMessage()); }