flutter - I need to call a function when I receive local notifications

582 Views Asked by At

I am trying to execute some code (a function) whenever I receive a minutely repeated local notification on android to mimic background tasks. (I want to track our employees when the app is in background, but without using background task packages)

So, simply I am doing a trick, and I don't know whether that works or not, but what I am trying to do is, I want to periodically send local notifications to myself, using **flutter_local_notifications **package, and I want to know if there is any way that I can execute some code when I receive the notification. (the local notification act as a background task and I want to do something when I get this local notification, to mimic using background tasks.)

I have tried a lot of packages for background tasks. Including alarm_manager_plus, background_location, and work_manager package. the best one was workmanager package, but the frequency of repeating the background task was 15 minutes, which is far more than I want. So, this trick came to my mind, if it works.

So, I thought if sending the scheduled local notifications for every minute and executing some code when I receive them works, then I will go with this approach.

So, I am asking, is there any way to execute some code when receiving local notification? or is there a better way of doing that?

Any Help is appreciated, thanks.

0

There are 0 best solutions below