Open leaf-node opened 1 month ago
I came across this issue on an Android 15 emulated device. After rebooting, the sticky notification showed up briefly, then disappeared. I saw the following in the adb log:
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: Failed to handle method call
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false: service com.example.app/com.dexterous.flutterlocalnotifications.ForegroundService
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.os.Parcel.readParcelableInternal(Parcel.java:5075)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.os.Parcel.readParcelable(Parcel.java:5057)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.os.Parcel.createExceptionOrNull(Parcel.java:3237)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.os.Parcel.createException(Parcel.java:3226)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.os.Parcel.readException(Parcel.java:3209)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.os.Parcel.readException(Parcel.java:3151)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.app.IActivityManager$Stub$Proxy.startService(IActivityManager.java:6393)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1960)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.app.ContextImpl.startForegroundService(ContextImpl.java:1935)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:832)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java:1128)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:700)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.startForegroundService(FlutterLocalNotificationsPlugin.java:2187)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1521)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.os.Handler.handleCallback(Handler.java:959)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.os.Handler.dispatchMessage(Handler.java:100)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.os.Looper.loopOnce(Looper.java:232)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.os.Looper.loop(Looper.java:317)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at android.app.ActivityThread.main(ActivityThread.java:8705)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at java.lang.reflect.Method.invoke(Native Method)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
10-03 21:48:53.188 2576 2576 E MethodChannel#dexterous.com/flutter/local_notifications: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
I started the app and rebooted again. This time the foreground started, a regular notification was created, and the foreground notification stayed in place. This might be an issue with flutter_local_notifications
.
https://developer.android.com/about/versions/15/behavior-changes-15#fgs-boot-completed
Basically, some service types will not be able to start a foreground service from the background after a reboot. For instance, I use the following code in my
AndroidManifest.xml
file, and that is no longer covered:https://developer.android.com/develop/background-work/services/foreground-services#background-start-restriction-exemptions
According to the above, it should still be possible to work around this issue by asking or helping users disable battery optimization for your app.