Is it possible to receive FCM push notifications when app is killed? - android

I am developing an e-mail app in which I want that the user will get a push notification as soon as they receive new email. And for that purpose I am using FCM. I have just tried push notifications using FCM by following this link: https://www.youtube.com/watch?v=XijS62iP1Xo&t=6s in order to test what features FCM provides. But the problem I face is that the device receives push notifications when app is either in foreground or background but it won't receive any push notifications when the app is closed (swipe or clear from the task manager). I don't know how to achieve this via FCM? I want to receive push notifications just like the WhatsApp and Facebook apps.
Every kind of help is appreciated. Thanks in advance.

There are 2 types of push notifications: Data messages and Notification messages.
If you are using the Data messages you will be in charge of handling the received message and present a notification to the user (if needed of course). But in this case you might miss notifications when your app is closed.
If you are using Notification Messages, FCM is handling the message for you and directly displays a notification if the app is in background/closed.
Please see more here.

It is not possible to receive a push notification in an app that has been killed/stopped by "Force stop" in application settings:
Let me quote the response I got from Firebase Support when I posed them that question:
The Android framework advises that apps that have been stopped (i.e.
killed/force-stopped from Settings) should not be started without
explicit user interaction. FCM follows this recommendation, and thus
does not deliver messages to stopped apps. Here are some documentation
that discuss this topic:
Life of a message from FCM to the device Using Firebase Cloud
Messaging with Android O
This confirms what I observed when I tested it using a simple app.
But you should be able to get push messages from FCM when the app is in background, even if it was swiped off from Recents screen, or after system reboot. That is, unless the manufacturer made the swipe gesture to work the way "Force stop" does on your device. How you receive it in the background depends on whether the push notification contains the "notification" payload:
If it does, you will receive the "data" only if user taps on the notification and it will be delivered in the Intent extras to the activity launched by the notification action.
If it doesn't, you will receive the notification in onMessageReceived just like you do when the app is in foreground.
Some other cases when your app is not killed, but still may not receive push notifications:
there can be delays because of Doze mode if you don't use high priority for the push message
message might not be delivered if your app is background restricted

Yes only if you consider sending data payloads not notifications and handle it in onMessage()
get more info here
How to handle firebase notification on background as well as foreground?

If your App is Killed or in background,check for the Payload in your Launching Screen
in My case it is MainActivity so in onCreate() Check for Extras:
if (getIntent().getExtras() != null) {
for (String key : getIntent().getExtras().keySet()) {
Object value = getIntent().getExtras().get(key);
Log.d("MainActivity: ", "Key: " + key + " Value: " + value);
}
}

Related

Send request to an other android device in a app

I am currently trying to make a personal location application between 2 devices on Android.
The concept is simple: I install my application on my phone as well as on that of my wife and each can geolocate the other.
(This application is strictly personal)
To achieve this, I thought of using sending notifications by FCM.
Telephone A sends a request to telephone B which listens via a service for the reception of a message.
When phone B receives the request, it returns the GPS coordinates via FCM so that phone A displays them on a MAP.
(I also have the possibility to store the coordinates in a database instead of sending back an FCM message)
But FCM's documentation says:
"When your app is in the background, notification messages are displayed in the system tray, and onMessageReceived is not called. For notification messages with a data payload, the notification message is displayed in the system tray, and the data that was included with the notification message can be retrieved from the intent launched when the user taps on the notification."
Of course, this reduces the scope since it forces the user of the phone receiving the notification to click on it to activate the actions of the service.
Can FCM still meet my needs through another channel?
Are there other options to send a "request" to another phone?
(I know that this kind of application exists on the PlayStore, but I want to try to make mine :-))
The key word in that section from the documentation you quote is notification messages. Firebase Cloud Messaging supports two types of messages:
Notification messages, which are display by the system when the app is inactive - and delivered to your application code when the app is active.
Data messages, which are always delivered to your application code.
It sounds like you'll want to use data messages for this use-case

silent push notifications in react native app

We are working on a react native app, in which we have some features where we can do some actions using silent push notifications. we are using react-native-firebase for that.
For sending push notifications we are using firebase cloud functions, here is the payload structure.
let payload = {
token: pushToken,
priority: normal,
data : {
RequestUserID : event.params.requestId,
}
We are not getting callbacks for app when its running in foreground or background ?
Any solution to get silent push notifications so that we can perform some tasks, when app is in foreground, background or killed ?
I don't think it's possible to not give an alert (unless the user disabled them) when the app is backgrounded or killed and receives a push notification. You could send data and run a task while the app is backgrounded if you use a websocket. That would not send an alert. If the app is closed, you won't be able to make it do any task.
You need to send you data in a notification payload instead of in a data payload. As seen in https://rnfirebase.io/messaging/usage

Can a push message sent by google cloud messaging be hidden from the app user?

I'm just going through the concept options of the Google Cloud Messaging System https://developers.google.com/cloud-messaging/concept-options and I saw this:
App behavior when receiving messages that include both notification and data payloads
depends on whether the app is in the background, or the foreground —essentially,
whether or not it is active at the time of receipt.
- When in the background, apps receive the notification payload in the notification tray,
and only handle the data payload when the user taps on the notification.
- When in the foreground, your app receives a bundle with both payloads available.
Is it possible to send a push message to specific android device and then verify its content by the app's logic?
And then if the content is verified by the app and it's correct - notify the user, in other case stay silent, dismiss the push msg and don't even show the notification icon?
Thanks!
You have to track the gcm type, for what such gcm gets called, depend on that you can show & hide notifications.
To show notification to user for push the control is in your hand only. Just apply the check that you want to and if the condition satisfies only then generate the notification.

What is the difference of "Notification" and "Push Notification" in Android

I want to use Notification in my Android app but I don't know what is the difference between Notification and Push Notification in Android.
I searched the web about this title but all of them talk about differences in apple products.
Can anyone remark where I should use Notification and where I should use Push Notification?
The main difference between push notification and notification is that the latter are created internally from an application on the device that wants to show user some information, a reminder, some news or updates, and so on. Push notification are "messages" sent from outside the device, for example a server, that triggers an application of the device (which usually handle the incoming message and transform it in a "normal" notification to be displays in the system tray). This is usually made through a public service such as Firebase Cloud Message ( https://firebase.google.com/docs/cloud-messaging/ ) of Google or a proprietary service such as the one that is used by the most common chatting application (Whatsapp, Telegram, ...) .
Indeed the most common example of push notification is the whatsapp notification of new messages that shows up in your phone when another user has sent you a message (so the message comes from outside your phone). Instead, the basic example for normal notifications are the alarm's notifications or the calendar's notifications.
Notification: When notifies you about the same application state, example: In a game application: "You have 10 days trial, or a product that provides the application".
Push Notification: When notifies you in real time about events related to users, eg solical In an application, "A message from a friend, a new invitation, an event".

How are Android GCM push notifications processed?

I am working on a Cordova Android app that handles push notifications using the PushPlugin. The app will correctly receive push notifications when the app is open. However no push notifications are received (or at least handled) if the app is not open.
This makes some sense given that the plugin has code that specifically handles receiving push notifications. What does not make much sense to me is why this code even exists at all. Before building this app, I assumed that the OS had some sort of queuing system that received any/all notifications.
Does a notification queue exists in Android that handles push notifications for all apps or does each app need to handle the notifications on their own.
Can Android apps process push notifications while closed?
Can Cordova Android apps process push notifications while closed?
In Google Cloud Messaging (which is the push notifications mechanism used by the PushPlugin) each application decides how to handle the notification. When a push notification arrives to the device, GCM triggers a BroadcastReceiver in the recipient application, and the application is responsible for handling the notification data.
Android apps can process push notifications when closed unless they are explicitly stopped by the user (in which case no notifications will reach the app until it is restarted again by the user). If they leave the foreground by the user switching to another app or going to the home screen, the can still receive and process notifications.
Yes. According to the PushPlugin you posted a link to, it seems that they can. When the app is not in the foreground, the notification is handled differently - a notification is added to the notification bar, and when it is tapped, it should open the app.
With PushPlugin, when sending push notifications to GCM (for GCM to send them to the device) one has to include a msgcnt key value pair after the message key value pair in the payload value in the JSON message, like this:
{
"GCM":"{\"data\":{\"message\":\"hello\",\"msgcnt\":\"1\"}}"
}
or else PushPlugin will not handle the notification when the app is in the background. It has to do with the way the GCMIntentService.java file is written in the plugin.

Categories

Resources