Firebase Notification Sound with DATA Payload - android

I'm sending notifications with the Firebase API from my server and im using data: instead of notification:... When I use notification, the sound works. I just set sound = default and it plays when a notification comes in in the background.
When im using DATA, I still get the message, but no sound is playing when I set sound = default. Will I have to load my sound into the project as mp3? or is there something I have to do in my FiremaseMessagingService.java file onReceive?
It seems when I use notification in addition. ONY notification is used the data doesn't come through

The sound parameter is a predefined parameter for Notification payloads, wherein a Notification Message is (as per the docs):
FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys.
In other words, the system is the one that handles this automatically. So the behavior you are seeing is the intended behavior.
When using Data payload (from the same docs above):
Client app is responsible for processing data messages. Data messages have only custom key-value pairs.
You'll have to implement how the details in the payload have to be handled in your onMessageReceived() (this is presuming that your app is in foreground, you still have to be aware of how to handle the messages depending of your apps status). That includes the sound parameter you included.

Related

How do I send a high priority inbox style notification on Android using FCM?

I want to send a high priority notification to Android devices using FCM and have it displayed in the system tray as an Inbox style notification.
FCM does not allow you to configure the Android notification style server side, so I must send the send the android system notification client side, to use NotificationManager API to send an inbox style notification.
The only way to do this without an automatic default style notification is to use FCM data messages. But the Firebase Flutter docs (I am trying to implement a solution for this on Android Native and Flutter, but a Android Native solution will suffice) indicate that data messages are low priority...
From the flutterfire docs:
As mentioned above, data only messages are classed as "low priority".
Devices can throttle and ignore these messages if your application is
in the background, terminated, or a variety of other conditions such
as low battery or currently high CPU usage.
You should not rely on data only messages to be delivered. They should
only be used to support your application's non-critical functionality,
e.g. pre-fetching data so the next time the user opens your app the
data is ready to be displayed and if the message never gets delivered
then your app still functions and fetches data on open.
So it seems, based on the premises presented here, that it is impossible to send a high priority inbox style notification on Android. Is this correct?
I think you still can. Even though data message is normal priority by default, you can still manually set it to high as stated in the doc.

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

Stop overlapping Android Audio Notifications

When using FCM Notification Channels - it is no longer possible to change the Notification Sound when a notification arrives (using SetSound()). This is causing me a problem when my app receives a notification while the audio of a previous notification is playing. Our notification sound bites are 2-3 seconds long each, and when the second notification arrives, it cuts the first notification's audio off.
Instead of delaying the second notification from displaying, I would like for the second notification to display, but not play any audio. Is this possible?
I don't think you have that level of control over how Android displays/plays incoming notification messages.
The only approach I can think of is taking full control of the display of the messages in your own application code, by using data messages instead of notification messages.
Reminder: Firebase Cloud Messaging has two message types: notification messages, and data messages. Notifications messages are automatically handled/displayed by the OS when your app is not active, while data messages are always delivered to your application code.
From within your application code, you can then use the Android notification API to build the exact display of the message that you want, and display it exactly when you want it (within the notification settings of the user of course).

Android FCM - How to build a default Notification for a push with notification and data payload

FCM lets us send push messages with two kinds of payload (notification and data), which are handled differently on Android:
notification messages, which contain only notification data
data messages, which contain only custom data
notification+data messages, which behave differently depending on whether the app is in foreground or not
In the third case, if the app is in foreground, the message is handled by a custom FirebaseMessagingService subclass in onMessageReceived(RemoteMessage). Otherwise, the system (or, more precisely, Google Play Services), builds the push notification.
I'd like to build a notification in onMessageReceived(RemoteMessage) that would be identical to the notification that the system would build if the push was received while the app is dead or in background, ie. taking into account the notification data received in the push (RemoteMessage.Notification), the defaults set in the Manifest's meta-data, etc. Is there a method in the SDK that would allow that, or maybe a third-party library, or do I have to reverse-engineer it by myself?

Firebase Pull notification

I'm working with Firebase Cloud Messaging. I have a couple of question I was not able to understand from the documentation:
Android: Lets suppose the app is closed (not backgrounded: closed). If I send a notification with also the data payload, this data payload is passed to the activity through the Intent Extra
Messages with both notification and data payload, both background and
foreground. In this case, the notification is delivered to the
device’s system tray, and the data payload is delivered in the extras
of the intent of your launcher Activity.
What if the user does not tap on the notification? Is the data payload lost? Is there a way to retrieve it?
iOS/Android. Lets suppose the user disabled the notification and I sent a notification to the client: is there a way to retrieve (pull) the notification at the application start?
Thanks very much
If the app is closed (not in background) the onMessageReceived method is called when the notification is received and there you can retrieve the data payload with remoteMessage.getData().get("key_for_parameter"); where key_for_parameter is the name of the parameter that you send in the notification. This method is called even if the application is closed. However, take into account that the "onMessageReceived" is called only if you omit the "notification" param in the notification (look this post)
So once you have the params in the onMessageReceived you can look for an strategy to use them in your application like storing in the DB and you are not going to lose the data if the user does not click on the notification.
if your app in background, Firebase will not trigger onMessageReceived(). Why.....? I have no idea. In this situation, I do not see any point in implementing FirebaseMessagingService.
According to docs, if you want to process background message arrival, you have to send 'click_action' with your message. But it is not possible if you send message from Firebase console, only via Firebase API. It means you will have to build your own "console" in order to enable marketing people to use it. So, this makes Firebase console also quite useless!
There is really good, promising, idea behind this new tool, but executed badly.
I suppose we will have to wait for new versions and improvements/fixes

Categories

Resources