6

I know how to create notification and notification channel in an Android app.

I showed many examples that say create notification channel while you generate a notification from FCM listener. So when the app receives notification at that point it generates channel.

But I saw in many apps, it create all channels without receiving any notification.

Question: From where we should create a notification channel?

KENdi
  • 7,576
  • 2
  • 16
  • 31
Sanjay Kakadiya
  • 1,596
  • 1
  • 15
  • 32
  • 1
    Inside onMessageReceived in your FirebaseMessagingService.java – Anand Nov 20 '18 at 11:13
  • I personally create mine during my application's `onCreate()`. In the [Google Notifications sample](https://github.com/googlesamples/android-Notifications) they create it in the MainActivity. – AL. Nov 20 '18 at 11:15
  • Possible duplicate of [Correct way to create Notification Channels from Android O Api](https://stackoverflow.com/q/46294833/4625829) – AL. Nov 20 '18 at 11:20
  • @AL. If you notice in the [Google notification sample](https://github.com/googlesamples/android-Notifications/blob/master/Application/src/main/java/com/example/android/wearable/wear/wearnotifications/MainActivity.java), It will create a channel while generating a notification. – Sanjay Kakadiya Nov 20 '18 at 11:40
  • Which is created in the MainActivity. This is all up to your preferences. In the possible duplicate post, creating the notification channel before posting the notification is also fine. – AL. Nov 20 '18 at 11:49
  • 2
    Does this answer your question? [Correct way to create Notification Channels from Android O Api](https://stackoverflow.com/questions/46294833/correct-way-to-create-notification-channels-from-android-o-api) – Yogesh Umesh Vaity Nov 14 '19 at 12:03

1 Answers1

0

From the docs:

Creating an existing notification channel with its original values performs no operation, so it's safe to call this code when starting an app.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
inhogo
  • 253
  • 3
  • 9