flutter_background_service
flutter_background_service copied to clipboard
foreground service used to keep sending http requests when the app is killed but now wont for new android versions
Im using a foreground service that have 2 main tasks : 1: keep a ble connection with a device even if the app is killed 2:keep sending http requests (every 50 seconds I have requests to send) even when the app is killed
It used to work with all android versions, now it works only for old versions ( I tried with android 8.1.0 ) and it works perfectly as expected but wont for android 13, when i pause the app or kill it no http request is sent, but when i bring it up they all send simultaneously
this is the foreground service declaration
`const notificationId = 888; final foregroundService = FlutterBackgroundService(); NotificationService notificationService = Get.put(NotificationService());
Future
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< AndroidFlutterLocalNotificationsPlugin>() ?.createNotificationChannel(androidChannel); await foregroundService.configure( androidConfiguration: AndroidConfiguration( notificationChannelId: notificationChannelId, // this must match with notification channel you created above. initialNotificationTitle: 'Ally', initialNotificationContent: 'The application is recording', foregroundServiceNotificationId: notificationId, // this will be executed when app is in foreground or background in separated isolate onStart: onStart, // auto start service autoStart: true, isForegroundMode: true, ), iosConfiguration: IosConfiguration( // auto start service autoStart: false, // this will be executed when app is in foreground in separated isolate onForeground: onStart, // you have to enable background fetch capability on xcode project ), );`
this is the AndroidManifest.xml
`
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service
android:name="id.flutter.flutter_background_service.BackgroundService"
android:foregroundServiceType="connectedDevice|dataSync"
/>`
note that the foreground service launches correctly, and when i kill the app it keeps runing, only issue is http requests are paused
you can read at https://developer.android.com/training/monitoring-device-state/doze-standby