flutter_background_service icon indicating copy to clipboard operation
flutter_background_service copied to clipboard

Cannot invoke service from notification action callback

Open kaciula opened this issue 3 years ago • 4 comments

I've added a STOP action button for the foreground service notification and I receive the tap but the service does not receive the stopService message. Is this an issue or am I missing something?

@pragma('vm:entry-point')
  static void notificationTapBackground(
      NotificationResponse notificationResponse) {
    _debugPrint('notification tapped in background: $notificationResponse');
    DartPluginRegistrant.ensureInitialized();

    if (notificationResponse.actionId == stopServiceActionId) {
      _debugPrint('Tapped action id ${notificationResponse.actionId}');
      FlutterBackgroundService().invoke('stopService');
    }
  }
@pragma('vm:entry-point')
void onStartAndroidForegroundService(ServiceInstance service) async {
  _debugPrint('On start foreground service callback');
  DartPluginRegistrant.ensureInitialized();

  service.on('stopService').listen((_) {
    _debugPrint('Stopping foreground service ...');
    service.stopSelf();
  });
}

kaciula avatar Oct 26 '22 14:10 kaciula

I also facing this issue? Any one find solutions?

ohari5336 avatar Nov 22 '22 03:11 ohari5336

When I invoke from UI it's proper working, but not invoke from notification action button

ohari5336 avatar Nov 22 '22 03:11 ohari5336

When I invoke from UI it's proper working, but not invoke from notification action button

@ohari5336 Did you find any solution to this to invoke service from notification?

johnray016 avatar Feb 13 '23 10:02 johnray016

i have facing the same issue but scenario is different. I have to pause and stop the timer as notification action, when user click on the action button of notification, action is detected but when i tried to pass that notification response another side with getx then always getting response as getx controller is again registered but it is already registered and when i tried to stop and pause from ui then it is working fine. @johnray016 @ohari5336 , did you guys find any solution for this type of issue ?

Kesmi avatar Apr 12 '23 10:04 Kesmi