Use Flutter Firebase Cloud Message (notification) to trigger background task to get current device location and make API call even on app terminated - flutter

When I get Only data FCM notification, I want to get person location and send it to my API in all app states: Foreground, Background, Terminated.
When app is in Foreground I have no problem.
When app goes to Background I am not able to get device location and make API call.
I did not even test terminated because I had no success in Background yet.
What I am using for test is:
FCM: firebase_messaging
To create background task: background_fetch
On notification received I am creating background task (NOTE: It will be created on background or terminated states in this states, not sure if this is true, most probably not I think.)
here is what I receive when trying in background
**Questions:
Is it possible?
What kind of solution can you suggest?
what is wrong in my solution**
Thanks in advance

Related

HMS Push plugin - how to receive data message when the app is in killed state

Android - Huawei with HMS push plugin, HmsPushEvent.onRemoteMessageReceived this event was not triggered when app is in killed state. This event only getting called while app is in foreground and background state. Can you please tell which event will be called when app is in killed state.
Push Kit supports two types of messages: notification messages and data messages. After a device receives a data message, the device transfers it to your app instead of directly displaying the message. Your app then parses the message and triggers the corresponding action. Push Kit only functions as a channel, and the delivery of data messages depends on the resident status of your app. However, notification messages can still be delivered even if your app is not launched.
For the sake of saving power and not disturbing users, your app will not be launched by Push Kit after being stopped, and no data messages can be delivered to your app. In this case, you can determine whether to use notification messages based on your services.
To allow users to open a specified page of your app after they tap a notification message, proceed as follows:
Generate Intent parameters
Set intent in the message body on your app server
Register the Activity class to be started in the AndroidManifest.xml file of the app
Receive data in the customized Activity class
From: https://stackoverflow.com/a/64100678/14006527
Alternatively, you can set high-priority data messages to forcibly launch your stopped app to receive and process the messages. To do so, you need to apply for special permission by referring to the related description in FAQs.

Running background task when user stops using app and moved to another in Metro app

Hello I am having below requirement in my metro app. Can you please explain how to handle this?
User logged in to app by entering his login credentails.
Then user moved to another app and started working on it(still he is using machine).
He came back after 15 Min. Now, I have to throw error message say "Session Tiemout"
I tried using BackgroungTask - but not succeeded. Reason is I cant initiate background task OnSuspend().
Let me know how to implement this?
If you want the notification to happen when the app is activated again, then simply register the App Activation handler and check to see if your login has timed out.
If you want the notification to happen outside of your app you will need to use a toast notification with a scheduled notification.
Background tasks are for doing work in the background while the user is doing something else. It can't be used for notifications.

iOS: Receive media in background

I am developing SIP and VoIP based iOS application and requirement is that the application should be continuously running even in background also.I am using pjsip lib.
I know that to run the iOS application in bacground,we need this
Set UIBackgroundModes key in Info.plist with voip value
Created a handler that I passed to setKeepAliveTimeout:handler: for
keeping the connection alive
But I just want that if my application is running in background can I receive UDP packets over (RTP/RTCP),while I am keeping UDP port always open.
I have already gone through the posts:
iPhone VOIP in background
VoIP socket on iOS - no notifications received
But,I have not getting clear idea that can we get UDP packet continuously even the app is in background or foreground.
So that if there is any data is coming to iOS client app , the app should be able to notify the user.
Please give suggestions.
In order to run VoIP app at the background and register on a server one should use TCP on iOS. When something happens you can fire local notification.
I think you can set local notifications when the app is running in background and indicate the user of an incoming call through the notification. When the user enters the application you can show the incoming call.
In the below link, check
Background Execution and Multitasking and also Scheduling the Delivery of Local Notifications
IE since you have set the UIBackgroundModes key in Your Info.plist, your app will support long running tasks. So in the applicationDidEnterBackground method add a method which creates a UILocalNotification when there's a call. UILocalNotifications notifies the user with an alert message and a tone of your choice. So once the user is notified and user enters the app, the app will come to foreground where you can add the method for him to receive the call.
In the alert body of the LocalNotification you can send the caller's information to the user.
EDIT : Check out the answer of Paul Richter in this link, where he says
VOIP mode gives you the ability to have code running to notify you of a call coming in
but you're not going to be able to record audio from the background. If you look at how
Voip apps work, when a call comes in a Local Notification is sent informing the user
that a call is coming in. The User then must accept the call which will bring the
application to the foreground at which point from the audio side of things you can
activate your session and proceed with the phone call.
Although not completely related to the library you are using, he has given a decent explaination of the process.
Hope this helps.

How to get local notifications when app enters the background

I am new to iphone. I am doing Project in that i have struck in the middle because of local notifications concept.In my applications i am sending the request to the server and getting response for every 20 sec by using timer concept but when the application enter the background
how can we get the response from the server for every 20 sec by using local notifications.If anybody knows this concept please help me...
When App on background mode , you receive loacl notification, and you click yes button then
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif
this function is call and you get dictionary
NSLog(#"%#",[notif userInfo]);
and call the xml in this function.. and you can get resonance from your server very easily
Generally, your app doesn't get to execute in the background, and local notifications won't provide you the ability to execute in the background.
(There are exceptions to this, but they come with limitations. If you really need to ping a server every 20 sec because you're something like a VoIP app, you can declare that you're a VoIP app and set up a keep-alive handler for doing that ping. However, if you're submitting to the App Store, Apple will require that you're really implementing a VoIP-like app, and not just downloading new RSS feeds in the background or some such.)
What local notifications are for is getting the user's attention when your app isn't active. While your app is running, you can schedule a local notification to post a message to the user some time later (sort of like a calendar alarm). If you're using one of the supported background execution modes, you can use a local notification to get the user's attention right now. Either way, your app only gets activated if the user chooses to tap the notification.

Handling Push Notification While App is Open

I have my Push Notification running. It works. I receive a notification and use
application:didReceiveRemoteNotification:
to get the incoming data and then send the user to the necessary screen.
Problem is, if you are using the App and a notification is received, it jumps to the destination screen without giving any alert/sound/anything.
I could put an alert in application:didReceiveRemoteNotification:, but then that alert would appear every time, not just when the app is running.
Ideas about how to handle this?
I would recommend checking the applicationState property in UIApplication to determine if the app is running in the background or not.