Closed nicolasvahidzein closed 4 years ago
There are many factors in play that influence if a message on the client is actually displayed as a notification or not - while I don't immediately see an issue in the fields you're using (and the Firebase API is accepting it, so it's fine by itself), I also can't tell you what might cause the unwanted behavior.
My advice would be to try with the simplest possible message at first and then add the additional fields until it doesn't work as expected anymore.
If you're using an array, you pass it directly to Messaging::send()
(except, of course, there's a reason you're using RawMessageFromArray
instead of CloudMessage
)
$messaging->send([
'token' => $deviceToken,
'notification' => [
'title' => 'My title',
'body' => 'My body',
],
]);
One of the factors that might come into play: I'm testing FCM messages with Firefox on my computer. I receive messages as notification only if I'm on another tab - just having the browser minimized or hidden is not enough. I don't know what affects notifications on Android systems and when a message is delivered directly into the system tray or when an actual visual notification is triggered.
All in all, there's not much I can do from an SDK perspective, so I'm closing this issue - but feel free to continue the conversation or add your findings once you've figured it out to help others that might stumble upon this! 🙏
I guess i mispoke. Its working perfectly fine except its a silent notification. I want the heads up style. People say you need high priroty then they say you need sound. Its a mess. The they say omit the notification part. I was wondering if you own an android if you can send a sample message from kreit that confirm comes in as a heads up notification and not a silent notification. Otherwise i get them and your package is awesome. I was never faulting you.
Oh, I didn‘t think you did, but thank you so much for clearing this up anyway 🌺.
I unfortunately don‘t own an android device (and don‘t have an own application I could test this with), I only ever test with browser notifications 🙈.
What I do know is that a message definitely needs a notification with a title and a body to be displayed as a popular notification (I believe that’s what you mean with „heads up“ notification).
As I don‘t know for sure either, I can only ask questions as some kind of a „check list“ to clear possible issues - if you have already checked it, just ignore :)
I haven‘t more ideas at the moment, but if something comes to mind, I‘ll add it 🤞
Everything is tip top. All the answers to your questions is positive.
Not silent Enabled They arrive perfectly in all 3 situations running, bg, resume Simple works but shows the same as silent notification Yes reinstalled Yes correct token. It fails if token is old or unregistered or fake
If you compose and send a notification from the Firebase Console (in the Browser), does it work as you would expect it?
that's my problem, i don't have a baseline as FCM console removed the priority option. People say to send the notification with priority in data portion but it does nothing. Where do we set priority in fcm in your sdk? can it be somewhere else than in the android section of the raw message?
also, how do i set thisin Kreit?
"webpush": {
"headers": {
"Urgency": "high"
}
}
Also i found this: https://developer.android.com/training/notify-user/build-notification#Priority
private fun createNotificationChannel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val name = getString(R.string.channel_name)
val descriptionText = getString(R.string.channel_description)
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
description = descriptionText
}
// Register the channel with the system
val notificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}
How do i set this in kreit?
Thanks.
I don‘t know what the Android is all about, but from the backend we‘re limited/enabled to what the REST API supports, you can find the specification here:
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages
If you find that the CloudMessage
doesn‘t support one of these, please let me know. However you should be able to use the full specification if you pass it to the RawMessageFromArray
class.
Ok will revert back. For enum types what do i type since it cannot detect the associated classes?
What do you mean by „revert“?
You can continue to use CloudMessage
or RawMessageFromArray
, but the message payload must match the specifications of the REST API.
As for the enums, you can use their values, I don‘t know how enums work with Java, but in the case of e.g. NotificationManager.IMPORTANCE_DEFAULT
, use either the string 'IMPORTANCE_DEFAULT'
, the value you find behind that enum or use the correspondent value in the docs.
I can't explain this, i am not using the most complete api rest call in the history of humanity and still nothing.
https://stackoverflow.com/questions/61166309/android-heads-up-firebase-notification-not-working
I have no idea why android is so backwards like this. It should be extremely simple but no dice.
I can't explain this, i am not using the most complete api rest call in the history of humanity and still nothing.
https://stackoverflow.com/questions/61166309/android-heads-up-firebase-notification-not-working
I have no idea why android is so backwards like this. It should be extremely simple but no dice.
Hey @nicolasvahidzein , on your SO post you left a comment saying you found the solution. Can you please post it here so others can benefit.
Thanks,
Ping me on skype please nzein19. Ill show you and you can paste it here to help everyone. My time is too limited.
Hey everyone,
I struggled with this issue for a long time - turns out the issue isn't truly related to kreait/laravel-firebase
.
The issue is documented pretty well here: https://developer.android.com/develop/ui/views/notifications#ManageChannels
TL;DR - newer versions of Android require you to declare a notification channel to use if you want to use heads-up notifications, as the default channel that gets set up isn't capable of things like heads-up notification, or vibrate, or flashing light.
Set up a channel in MainApplication.java, like the following comment outlines: https://github.com/invertase/react-native-firebase/issues/2791#issuecomment-552616427
From there, just make sure to push your Notification to that channel on Android:
new FcmMessage(
notification: [
'title' => $title
],
custom: [
'android' => [
'notification' => [
'title' => $title,
'channel_id' => 'YOUR_CHANNEL_NAME',
]
],
Thanks to @nicolasvahidzein to pairing with me on this
Hope it helps
Thanks to both of you enabling others who might stumble upon this, four years (!) later! 🙏🏻
This is what makes this community amazing.
Hello, i am able to send a message via laravel to my app but when in the bg the notification is the default silent notification. My notification is on high but nothing changes.