On this page13 sections
  1. Prerequisites
  2. Learning Objectives
  3. 1. Notification Channels
  4. 2. Default Channel and Icon
  5. 3. The Click Action
  6. 4. The Icon
  7. Code Examples
  8. Common Beginner Mistakes
  9. Best Practices
  10. Practice Questions
  11. Practice Answers
  12. Key Takeaways
  13. Full Code (Copy-Paste Reference)

Lecture 010: Android Channel, Icon & Click Action

Category2: Push Notifications
Lecture010 of 014
Estimated video length14 min
TargetFlutter 3.44 · Dart 3.12 · FlutterFire (latest)
LevelIntermediate

Android lets you choose which channel a notification uses, which icon it shows, and what happens on a tap. We set all three in the manifest.

Contents

Prerequisites · Objectives · Lesson · Code Examples · Common Mistakes · Best Practices · Practice Questions · Answers · Takeaways · Full Code


Prerequisites

Lectures 002 and 006: the manifest, and receiving messages.


Learning Objectives

  • Know what a notification channel is
  • Set the default channel and icon with <meta-data>
  • Make taps open the app with a FLUTTER_NOTIFICATION_CLICK intent filter
  • Make a proper white notification icon

1. Notification Channels

Since Android 8, every notification belongs to a channel: a category the user can mute or change in Settings (for example "Promotions" vs "Order updates"). If a message names no channel, Android uses the default one in your manifest.

2. Default Channel and Icon

Inside <application>, before <activity>:

xml
<meta-data
    android:name="com.google.firebase.messaging.default_notification_channel_id"
    android:value="high_importance_channel"/>
<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_notification"/>
<meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/notification_color"/>
KeySets
default_notification_channel_idchannel used when a message names none
default_notification_iconthe small icon in the status bar
default_notification_colorthe icon's accent color

If the channel ID doesn't exist yet, FCM creates a channel called "Miscellaneous". To give it a proper name and importance, create it in code with the flutter_local_notifications package (AndroidNotificationChannel).

Some guides set the channel ID to FLUTTER_NOTIFICATION_CLICK. That works, but it mixes up two different things: a channel ID and a click action (section 3). Use a descriptive channel ID.

3. The Click Action

Inside <activity android:name=".MainActivity" ...>, Flutter already has the launcher filter. Add a second one:

xml
<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
    <action android:name="FLUTTER_NOTIFICATION_CLICK"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

When a message is sent with click_action: FLUTTER_NOTIFICATION_CLICK, Android opens the activity with this filter, your app, and onMessageOpenedApp / getInitialMessage fire. Notifications without a click_action open the launcher activity anyway; the filter matters for servers and older setups that set it.

4. The Icon

Android draws the small icon white on transparent: a full-color launcher icon becomes a white square. Make a proper one:

  1. Android Studio → right-click android/app/src/main/res → New → Image Asset.
  2. Icon type: Notification Icons, name ic_notification, pick a simple shape.
  3. Finish: it writes drawable-*/ic_notification.png.

And the color, in android/app/src/main/res/values/colors.xml:

xml
<resources>
    <color name="notification_color">#0175C2</color>
</resources>

Code Examples

Example 1: The Complete Manifest

xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

    <application
        android:label="notify_demo"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="high_importance_channel"/>
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/ic_notification"/>
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/notification_color"/>

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme">
            <!-- Flutter's existing meta-data stays here -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

        <meta-data android:name="flutterEmbedding" android:value="2"/>
    </application>
</manifest>

Send a test message with the app minimized: the status bar shows your white icon in your color, and a tap opens the app.


Common Beginner Mistakes

1. Meta-data inside <activity>: the Firebase keys belong directly inside <application>.

2. Using @mipmap/ic_launcher as the notification icon: shows a white blob. Make a Notification Icon asset.

3. Replacing the launcher filter: the app disappears from the home screen. Add the click filter as a second <intent-filter>.


Best Practices

  • One channel per kind of notification, with clear names users understand.
  • Keep the icon a simple silhouette.
  • Keep android:launchMode="singleTop" so a tap doesn't open a second copy of the app.

Practice Questions

  1. What can a user do with a notification channel?
  2. Where does the default_notification_icon meta-data go?
  3. What does the FLUTTER_NOTIFICATION_CLICK intent filter do?
  4. Why does a launcher icon look wrong as a notification icon?

Practice Answers

  1. Mute it or change its sound and importance in Settings.
  2. Directly inside <application>.
  3. Opens the app when a message's click_action is FLUTTER_NOTIFICATION_CLICK.
  4. Android draws the small icon in white only, so a colored square becomes a white square.

Key Takeaways

  • Every Android notification uses a channel; set a default in the manifest.
  • Set a white silhouette icon and an accent color.
  • Add the FLUTTER_NOTIFICATION_CLICK filter beside the launcher filter.
  • Firebase meta-data goes in <application>; intent filters in <activity>.

Full Code (Copy-Paste Reference)

No Dart changes this lecture: main.dart and the notification helper are unchanged from Lecture 009. The complete manifest, combining every earlier lecture's additions with this one's channel/icon/click-action meta-data, is already shown in full in Code Examples → Example 1 above. Copy that block as your android/app/src/main/AndroidManifest.xml.