App's notification button action in flutter - android

TLDR: Is it possible to reschedule notification when notification action button is clicked, without running the flutter app?
I have a flutter app that reminds of things via notifications using awesome_notifications plugin, and it has a 'remind later' button.
I have written the reschedule logic in app, but the click on notification button has to open the app in order to run the code. I have tried to open the app, reschedule, then close with exit(0), but it leaves the app in background - at least on Android, and it is preferable to not exit the app programatially anyways. Is it possible to reschedule notification without running flutter app?

It is not possible to reschedule a notification without running the Flutter app. When the notification action button is clicked, the Flutter app must be launched in order to handle the action.
One option you could consider is to use a background task to reschedule the notification. This would allow you to reschedule the notification without opening the app to the foreground.
To implement a background task in Flutter, you can use the flutter_background_fetch or workmanager package. These packages allow you to schedule a function to run in the background at regular intervals. You can use this function to reschedule the notification as needed.

Related

react native push notification snooze (react-native-push-notification)

I'm using https://github.com/zo0r/react-native-push-notification for local push notifications. It also includes an option to have some buttons on the notification("actions"), which I can press on.
However, when I'm getting a notification, to respond to that button(noti. action), the app should open(the only way I could work it around) and only then I can run my logic according to the action.
Because I have some troubles using react-native-push-notification for this(It simply doesn't work), I would like to implement this by myself.
This is the process I wish to have:
Push notification is showing up
The user clicks on the snooze button(same as an alarm)
The application is still in the background
The notification will be pushed again after some time.
What is the proper way to do such a thing? I have to run a background task that is fired when the user presses the snooze button. How can I use HeadlessJS for this? It is very easy to implement the snoozing logic with JavaScript, the problem is to fire it.

Show notification icon on status bar with React Native when app is not running on Android

I have a situation on my React Native app, where user can start a timer and isRunning and startTime states are stored in the app so that it can display current running time when the app is in foreground even though the user quits the application at some point and opens it again.
Is there a way to show notification icon on status bar when the timer is running, but user has quit the application to indicate that the timer is currently "running" (actually it is not doing any operations on background) on background?
I have encountered some apps that display a silent notification that is not directly closable after I have quit the app, but I haven't seen a situation where status bar notification is present (together with notification) until some condition is met after the app is quit by the user.
Is there a way to achieve this? I am using react-native-push-notification and Firebase to push notifications in my app overall.
React-Native manages only Active and Background/Inactive/Foreground state. When user kill the app. JS engine shuts down.
All you can use is Local Notification and Scheduled Notification. I also have one app in which user set a reminder time. And notification invoke at that specified time.
Using Firebase I guess you need to call api after some specific interval for push notification from server side.
I am not an expert in background services or android development but here is my thought... I believe you could dig in and write some java android code for a background unstoppable service (persistent on app close or background states). You can do this by creating a bridge and using native modules to manage your background services. I came across a great resource on medium that details the process of creating a background service, a broadcast receiver and maintaining Headless instance even when the app is closed or the device restarts.Hope that helps you achieve your goal.
Edit
This ready made package will help you with better. Check it out. You actually don't have to write native android java code at all.

How to run a background service in cordova

I need to know about how to run a background service to give notifications in cordova mobile application. I went through a plugin this but in that example when i clicked the 'Interval' option which is triggering notification for every minute when only app was opened or paused. It wasn't triggering any notification when app was killed(Swipe out from recent tasks) on background. So is there any alternative option to run the process in background in cordovaapplications
According to phonegap/Cordova documentation their is no way to run
background service because phone can not execute javascript when your
app is not running.Yet no plugin was available to perform this task

ngCordova LocalNotification plugin

I'm using the ngCordova LocalNotification plugin in my Ionic app and I am trying to get it to repeat but with a random time span.
For example the user will trigger the notification to launch in 1 minute, and after that I would need to have the notification launched again in another 2 minutes (hypothetical example, in real life scenario the time span would be much higher, ie a couple days).
So far I can get the notification to execute for the first time.
Then, I am using the $cordovaLocalNotification:trigger method to detect when the notification was triggered and inside of that method I have a code to schedule a new notification.
All of this works, but in order to launch whatever it is inside of that method's body, I have to acknowledge the notification on my device and click on it, then it launches this method.
So I am wondering if there's a way to have it schedule a new notification without me having to open the previous notification?
All of this has to happen locally on the device and the notification should persist even if the device is rebooted. Thanks a lot!
When the application go in backround, the webview stops the javascript execution. When you click on the notification, the app became a foreground process and javascript continue the execution.
So it seems that it works only when you click on the notification (that open the app) because only when the app is opened, the js code is executed.
You could double check this if you don't click on the notification, opening the app after the notification is displayed (without clicking it).
To clear all the triggered notification you could use the getTriggeredIds(scope) method to get all triggered notification IDs and the clear(ids, scope) method to clear them.
See the localNotification plugin documentation for more information.

How to achieve this in Android?

I am looking at Avast, Lookout for example and I am trying to understand the concept of the implementation. So it is more like asking for direction for me.
Persistent App icon in Notification bar.
Am I correct to say there are function NotificationManager is able to do it?
Scan virus during app installation, I am not interested in virus scanning but the triggering mechanism.
Some kind of Android service bind to the main app?
Main app that can be bring up in the Notification menu.
A main app that remain trigger action to the bind services?
So what do I need to read to understand? NoticationManager, Services and ??
In short, I want to load a icon in the notification bar that can bring up my app. There is a background service that perform specific task for a set interval.
Yep, NotificationManager and Notification can help you with that.
You just need to create the notification with flag FLAG_ONGOING_EVENT (to make it persistent). Even better if your service IS REALLY performing some long-running task, if so, you can start your service via Service.startForeground which needs some 'ongoing' notification for running (notification is required to notify the user that there is some work going now).
For triggering app install event, you can use BroadcastReceiver with filter by Intent.ACTION_PACKAGE_ADDED.

Categories

Resources