0

In Firebase Cloud Messaging docu, you can read that is mandatory:

Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel.

Caution: If you target Android 8.0 (API level 26) and post a notification without specifying a notification channel, the notification does not appear and the system logs an error.

*https://developer.android.com/training/notify-user/channels.html#java

Then, why when you send a notification from the FCM panel for cloud messaging the section for specifying the notification channel is marked as optional?

enter image description here

And also, I found this comment that appears to confirm that is optional and will work without specifying a notification channel in code and in FCM console:

(Optional) From Android 8.0 (API level 26) and higher, notification channels are supported and recommended. FCM provides a default notification channel with basic settings. If you prefer to create and use your own default channel, set default_notification_channel_id to the ID of your notification channel object as shown; FCM will use this value whenever incoming messages do not explicitly set a notification channel. To learn more, see Manage notification channels.

*https://firebase.google.com/docs/cloud-messaging/android/client

Then, it's optional? or it's mandatory? Will work without creating notification channels? or will not work? It's very frustrating...

NullPointerException
  • 36,107
  • 79
  • 222
  • 382

3 Answers3

1

Add this

<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>

to manifest file if you wish to show the message above api level 26. Otherwise the system will log error on devices having API 26+. It is optional means, you can send message, but the device will not show it if devices API level 26+. Optional really means use notification channel if you opt to show message otherwise the system only receive message not the user.Most of their documentations are always confusing like policy warning ... lol.

Joseph V
  • 11
  • 2
0

Notifications without the channel in Android O will not work since the app developer needs to specify the channel. So the notification channel is mandatory in Android O and above.

Devices with API 26 and below the Notification Channel is not required.

What's the purpose of notification channels?

Notification channels enable us app developers to group our notifications into groups—channels—with the user having the ability to modify notification settings for the entire channel at once. For example, for each channel, users can completely block all notifications, override the importance level, or allow a notification badge to be shown. This new feature helps in greatly improving the user experience of an app.

Read more about notification Channel

Eugene Ogongo
  • 335
  • 3
  • 12
  • please, check my question carefully, in the official documentation they are telling two different versions for Android 8.0. "(Optional) From Android 8.0 (API level 26) and higher, notification channels are supported and recommended." They tell that are optional also for 8.0. – NullPointerException Nov 09 '19 at 09:19
  • Hey, notification channels are a must in android O. You can declare one on your application manifest as the default one for firebase or you can supply one that is already created in your application in the Android Notification Channel input on firebase Console – Eugene Ogongo Nov 09 '19 at 09:23
0

For applications targeting API 26 or higher notification channels are mandatory.

FCM is not the only way to generate notifications, you can also create not FCM related ones in your code.

If the creator of a FCM notification doesn't assign a channel then the system will assign a default one.

For a not FCM related notification created in your code if it doesn't have an assigned channel it will not be shown.

from56
  • 3,976
  • 2
  • 13
  • 23
  • and what happens if with android 8 or higher i dont create a channel and I send a FCM push from the FCM push panel without specifying the optional channel? will reach the device? – NullPointerException Nov 09 '19 at 10:02
  • The system will assign a default channel and it will be shown – from56 Nov 09 '19 at 10:05
  • perfect, I tested it and it have been received in a Pixel with Android 10. So... then notification channels are simply optional... why then people think that they are mandatory? and why in some parts of the docu google says they are mandatory? – NullPointerException Nov 09 '19 at 10:33
  • They are mandatory. Optional from the FCM notification composer, mandatory to be shown. – from56 Nov 09 '19 at 10:35
  • I dont understand your last comment. In your previous comment you told me that if i don't specify a channel, they will be shown because it will use a default channel (already present by default, not created by me). And I tested it and it successfully be shown. Then, why now you are telling me that it is mandatory to create and use channels to be able to display notifications? – NullPointerException Nov 09 '19 at 10:46
  • Because if a notification does not have a channel, either the one assigned or the one assigned by default then it will not be shown, so for a notification to be shown the channel is mandatory. I don't find any contradiction in Google documents. – from56 Nov 09 '19 at 11:04
  • do you mean that if I'm not assigning one, in de backend is being assigned the hidden default channel to make it working? If so, that is perfect. Is what i understood in the third comment. – NullPointerException Nov 09 '19 at 11:33