Stop overlapping Android Audio Notifications - android

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).

Related

Android : What priority is a mixed FCM message

Android alert notification messages are "High" priority by default.
Android data only notification messages are "Low" priority by default.
What priority is an alert notification, which also carries data (using content-available).
We require high priority notifications, however, it seems that when our App is in the background and a notification arrives, the Title/Body are consumed by the OS. This means that when the user selects the notification from the notification tray, this information is missing in the provided Intent.
We are therefore obliged to pass these (Title/Body) fields as data, with every high priority alert notification.
Does doing this affect the priority of the message, and, if it does affect it, what is the workaround?
Also, is there a way of discovering what priority was actually used for a received message?
On the sender side, you send a mixed message with the priority you decide. There is no impact.
The difference is just, that when a message contains data you get the callback in your FCMService, so your app wakes up.
If there is no data part, your app will not wake up before the user clicks the notification.
In general, this is the only question that matters: Do you want to wake up when the message arrives or just when the user clicks the notification?
If your message contains data, the OS will not post the notification. This part is up to you then.
We work with data-Message only as we want to have more control over the notification and we need to wake up when it arrives.

On Oreo, is it possible to mute individual notifications belonging to the same notification channel?

I have a bunch of notifications for new messages (MessagingStyle, one notification contains one or more messages with the same user), and I want to play sound when a new message arrives now. Sometimes I want to update the notification silently, though. For instance:
On system boot up, I want to present old messages to the user without sound
When the application is not connected, I want to update the notifications to remove the “Reply” button, and vice versa
When an application receives a message that was posted some time in the past, I don't want to alert the user as they may have read the message elsewhere.
It works fine on L but Oreo seems to be playing sound for every notification fire or update. Is there a way to work around this behavior?

Android - how to programatically set notification sound for future push notifications sent by FCM

My server is able to send FCM push notifications to my Android app users. The notifications are successfully delivered with default notification sound.
However, I want the app user to select sound from Ringtone Picker in the Preference screen.
I have been able to show Ringtone Picker in the Preference screen, but I don't know how to set the selected sound URI for future push notifications
So that when the future push notification of this app is received, the sound that user selected, should be played.
Please advice
Try using this? I assume in your app you are dealing with this class and library.
https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setSound(android.net.Uri)

Firebase Notification Sound with DATA Payload

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.

Cancelling a notification received in background from GCM (Android)

I'm using Google Cloud Messaging to receive new orders into an app. I'm trying to handle cases where the same order is sent twice. I just want the second receipt to be ignored, unfortuntately when the app is in the background I dont seem to be able to cancel the notification (ie it still makes a noise and sends a message). The app works fine when in the foreground, putting cancel notification code in my GCMBrodacastreceiver doesnt seem to do anything. Am I missing something?
NotificationManager mNotify = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotify.cancelAll();
You can set the "tag" field in the notification payload. If you use this the incoming notification will just update any existing one with the same tag.
cancelAll() will dismiss the notification, but your code may not be invoked when the app is in the background as the notification will be posted without your app's code running. One option would be to have your server not send the notification if it has already sent one recently.

Categories

Resources