On this page13 sections
Lecture 010: Android Channel, Icon & Click Action
| Category | 2: Push Notifications |
| Lecture | 010 of 014 |
| Estimated video length | 14 min |
| Target | Flutter 3.44 · Dart 3.12 · FlutterFire (latest) |
| Level | Intermediate |
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_CLICKintent 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>:
<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"/>| Key | Sets |
|---|---|
default_notification_channel_id | channel used when a message names none |
default_notification_icon | the small icon in the status bar |
default_notification_color | the 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:
<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:
- Android Studio → right-click
android/app/src/main/res→ New → Image Asset. - Icon type: Notification Icons, name
ic_notification, pick a simple shape. - Finish: it writes
drawable-*/ic_notification.png.
And the color, in android/app/src/main/res/values/colors.xml:
<resources>
<color name="notification_color">#0175C2</color>
</resources>Code Examples
Example 1: The Complete Manifest
<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
- What can a user do with a notification channel?
- Where does the
default_notification_iconmeta-data go? - What does the
FLUTTER_NOTIFICATION_CLICKintent filter do? - Why does a launcher icon look wrong as a notification icon?
Practice Answers
- Mute it or change its sound and importance in Settings.
- Directly inside
<application>. - Opens the app when a message's
click_actionisFLUTTER_NOTIFICATION_CLICK. - 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_CLICKfilter 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.