Skip to content

Update notificationText and notificationTile text #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yusmi25 opened this issue May 17, 2021 · 5 comments
Closed

Update notificationText and notificationTile text #1

yusmi25 opened this issue May 17, 2021 · 5 comments

Comments

@yusmi25
Copy link

yusmi25 commented May 17, 2021

hello, great package.
Can I update the notification text, because I'm using counting timer on the notificationText
thanks.

@Dev-hwang
Copy link
Owner

hello, great package.
Can I update the notification text, because I'm using counting timer on the notificationText
thanks.

Try updating to flutter_foreground_task: ^1.0.8.

And using the update function, you can update the notification title and content.
Whenever the notification is updated, a sound or vibration may occur.
Therefore, it is recommended to set channelImportance and priority to LOW or less.

  final flutterForegroundTask = FlutterForegroundTask.instance.init(
    notificationOptions: NotificationOptions(
      channelId: 'notification_channel_id',
      channelName: 'Foreground Notification',
      channelDescription: 'This notification appears when a foreground task is running.',
      channelImportance: NotificationChannelImportance.LOW,
      priority: NotificationPriority.LOW
    ),
    foregroundTaskOptions: ForegroundTaskOptions(
      interval: 5000
    )
  );

  int count = 0;
  void startForegroundTask() {
    flutterForegroundTask.start(
      notificationTitle: 'Foreground task is running',
      notificationText: 'Tap to return to the app',
      taskCallback: (DateTime timestamp) {
        print('timestamp: $timestamp');

        count++;
        flutterForegroundTask.update(
          notificationTitle: 'count: $count',
          notificationText: 'count: $count'
        );
      }
    );
  }

The update function does not have to be implemented inside taskCallback. However, please use it after calling the start function.

@am2074
Copy link

am2074 commented Aug 2, 2021

This solution provided does not work anymore for anyone trying to do what the original user wanted to solve. I'm using the latest version of this and this solution does not activateFlutterForegroundTask.update. Is there anyway to fix this?

@Dev-hwang
Copy link
Owner

@am2074

Many things have changed since version 2.0.0. check readme.

@obidano
Copy link

obidano commented Oct 25, 2021

flutter_foreground_task: ^3.0.0
The notificationTitle and notificationText are not updating

await FlutterForegroundTask.startService(
      notificationTitle: 'xxxxxx',
      notificationText: 'yyyyyyy...',
      callback: startCallback,
    );

@Dev-hwang
Copy link
Owner

@obidano

To update the notification title and text when the foreground service is started, you need to use the updateService function.

If the notification title and text are not applied in the startService function, check whether the iconData data actually exists in the AndroidNotificationOptions setting. For testing, remove the iconData setting and run the service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants