push notification flutter in background service - android

I need run a dart code for each 10s even if the application is closed. It's possible? in flutter
I need to fetch data every 10s if any change the push notification show to the users
i am using a custom API rest (asp.net core) for data connecting
On click of the notification should open the app.
I have not worked on Push Notifications in the past and would be great if you could help me with where to start. Links to any documentation or advice would be great.
Thanks in advance.

Related

Flutter – push notifications not working in the background when app is killed

I'm trying to build a real time chat app.
I have integrated https://pub.dev/packages/flutter_local_notifications package for push notifications and this works.
I am NOT using Firebase, i am using my own custom backend that uses https://socket.io/ for real time chatting.
I want to receive a push notification when the user sends a chat message. Push notifications work when the app is in foreground or background. However when i terminate my app from the process (app is killed), the push notifications no longer work.
Is there a way to send push notifications without using Firebase so that i can receive notifications even when my app has been terminated from the process? I need this to work both for android and ios.
Basically, I don't recommend any solution for push notifications instead of firebase.
But if you have your reasons to use socket in this case I suggest you take a look into this package how it uses background service and tries to implement your own way to setup socket-based notification background service.
https://pub.dev/packages/background_locator

Flutter Push notification to iOS & Android without firebase?

I wonder how to push notifications to my Flutter app users in both Android and iOS devices Without using any external service like Firebase or OneSignal?
I want to implement a code in PHP which can send push real time notifications to all/spesific users in my Flutter app which works in both Android and iOS.
I found some solutions like flutter_local_notifications with workmanger which can fetch the API in the background only minimum 15 minuts. Workmanger is Not good solution because its work only during 15 min and it will consume the battery and internet.
I need an efficient solution to my flutter app for both Android & iOS devices, which can listen on real time to the coming messages from the server even when the app is closed.
How to fix that? thanks
iOS
You will always need to integrate with Apple's Push Notification Server (APNS) if your app needs make API calls in the background. The reason is that once an app is put into the background, iOS will often put the app to sleep soon afterwards.
The correct approach to this is to use a silent push notification to wake up the app. When received, no message is shown on device but the app get's about 30 seconds in order to make API calls.
In your case, the app can make the API call and then schedule a local push notification to display your message.
Background updates via push notifications
Scheduling local push notifications
Android
It looks like WorkManager is your best bet. I don't see how it can affect battery.
FYI
You don't need to use Firebase or OneSignal for push notifications, silent or otherwise. They are simply 3rd party services that interact with the official Apple or Google Push Notification Servers.
Unfortunately, I think this is not possible. Even OneSignal uses the Firebase API to deliver the notifications, as you can see here. For all other solutions, you will have to balance the update frequency with internet use and battery consumption.

Phonegap(cordova) Pushplugin Silent Notification - Android

I am working on a chat application using phonegap for android, which is already running over web. I am sending messages through pushnotification and everything is working fine and notification is coming in status bar with default device sound setting. Now I want to sync some data from server without notifying user, means I need a notification that should just tell me that there is some new data on server to sync, without having status bar notification. I searched over web but couldn't found anything which can help me.
Any help would be great..
Thanks
Jaya
You could modify the plugin to not create a notification if a certain variable is set.
If you are using PushPlugin:
A notification is created only if you send message in the payload. But you will receive the payload in your application's callback. You can use this effectively to communicate with your application with having to implement anything additional.

Android/ios async notification using cordova

I'm building an app using cordova most likely Android/ios. My app need to send a reminder to the user and ideally that notification would bring the user to the app. The app might and is most likely not running when the notification kicks in. The next notification is knows by the app in advance and does not need Internet to find the content of the notification. Currently the data is in localstorage so might not be accessible by native code ?
The way I see it would be a cron job running everyday at a specific (configurable) hour, then notify the user if it has to.
I wonder what is the best way to achieve this. Here's what I've found so far:
Dialog/notification plugin in cordova, but that seems to kick in only when the app is running.
Push notification plugin : from a first sight perspective, this seems to be Internet pushed notification and not really what I need.
Specific code for different platform. In Android : a service using an AlarmManager to kick in at the right time and send a Notifications when necessary. This would need access to the localstorage in native code, or store the data elsewhere and is platform dependant, but looks like the only solution so far.
Something else ?
What is the best solution ?
Thanks
I think you need this plugin. Katzer It runs locally, so no internet dependency. Can repeat itself monthly, weekly, daily etc. Notification can be given when app is closed.

Air iOS/Android push notification remember when app launches

I have an app built for iOS and Android which has push notifications. Everything is working great however I was wondering if there is a way to store the data of the push notification in the app so that when users launch the app after receiving a notification I can show them the message again?
Basically I allow users to share information and/or chat amongst their friends. If they receive a notification when the app is in the background it comes through as a normal push message but when they launch the app I would like to direct them to the chat feature to see the message again.
I am storing the messages sent in a remote DB but seeing as they have already received the payload it doesn't make much sense for the app to call the remote DB to retrieve the same message.
I am using Distriqt's extensions in AS3 and Air 3.5.
Cheers
I asked Distriqt's support for the same thing a few weeks ago and they explained that there is no way to get the information of the push notification message while the app is closed so they suggested this :
- when the user opens the app, you call your server to check if they haven't missed anything, and get the data from there. If there has been a push, you display the push message as if it was received with the app in the foreground.
It's a bit tricky and not very satisfying but it works.. As long as the user follows the path.
If your user receives the push and chooses not to open your app, he will still get the push message in your app next time he opens it.
I was having trouble figuring this out too but I found a solution! Basically if a user launches an app (not running in the background) by way of a notification it comes through in the Invoke event, not the usual Notification event. So do this:
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invoked);
private function invoked(evt:InvokeEvent):void
{
if (evt.reason == InvokeEventReason.NOTIFICATION)
{
var payload:Object = Object(evt.arguments[0]);
// do stuff
}
}
That's pretty much it. There's more detail in this blog post here: http://blogs.adobe.com/airodynamics/2012/05/29/push-notifications-support-in-ios/
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, invoked);
doesn't work correctly for Android push notification. Android starts with InvokeEventReason.standard all the time, so we cant receive message. It works only for iOS.

Categories

Resources