Dev-hwang / flutter_foreground_task

This plugin is used to implement a foreground service on the Android platform.
https://pub.dev/packages/flutter_foreground_task
MIT License
149 stars 108 forks source link

Crashing on Android API Level 34 (Android 14) #175

Closed tentenponce closed 12 months ago

tentenponce commented 1 year ago
E/AndroidRuntime( 5973): java.lang.RuntimeException: Unable to create service com.pravera.flutter_foreground_task.service.ForegroundService: java.lang.SecurityException: com.sample.app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
E/AndroidRuntime( 5973):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4664)
E/AndroidRuntime( 5973):    at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
E/AndroidRuntime( 5973):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2264)
E/AndroidRuntime( 5973):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 5973):    at android.os.Looper.loopOnce(Looper.java:205)
E/AndroidRuntime( 5973):    at android.os.Looper.loop(Looper.java:294)
E/AndroidRuntime( 5973):    at android.app.ActivityThread.main(ActivityThread.java:8177)
E/AndroidRuntime( 5973):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5973):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/AndroidRuntime( 5973):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
tentenponce commented 1 year ago

related issue: https://stackoverflow.com/questions/74272587/android13-receiver-exporteds-explanation-is-correct

Possible to be fixed by adding RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED as flag on registerReceiver(). Can this be a optional parameter (with a default value RECEIVER_NOT_EXPORTED)?

GabrielAraujo commented 1 year ago

I have some users also experiencing it. I'm using the following

return WillStartForegroundTask(
                        onWillStart: () async {
                          return true;
                        },
                        androidNotificationOptions: AndroidNotificationOptions(
                          channelId: 'service_runner',
                          channelName: 'Service Runner',
                          channelDescription:
                              'Used to spin up foreground services, preventing the app from being killed.',
                          channelImportance: NotificationChannelImportance.LOW,
                          priority: NotificationPriority.LOW,
                          isSticky: false, // important
                        ),
                        iosNotificationOptions: const IOSNotificationOptions(
                          showNotification: false,
                          playSound: false,
                        ),
                        foregroundTaskOptions: const ForegroundTaskOptions(
                          interval: 5000,
                          isOnceEvent: false,
                          allowWakeLock: false,
                          allowWifiLock: false,
                        ),
                        notificationTitle: 'Service is running',
                        notificationText: 'Tap to return to the app',
                        child: child!,
                        ),
                      );