W/FirebaseMessaging: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used
J

6

42

Our app now has targetSdkVersion 26 (Android 8) and the app uses FCM push notifications. When app is in the foreground state the push notification is working well. The issue appears while clicking the notification when the app is not in the foreground state. I just added the metadata in manifest but still got same error.

AndroidManifest.xml

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

MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 */
private void sendNotification(NotificationModel notificationModel) 
{
    Intent intent;
    if (notificationModel.getAppLink() != null) 
    {
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(notificationModel.getAppLink()));
    } else 
    {
        intent = new Intent(this, NoticeActivity.class);
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);

    if (notificationModel.getAppLink() != null) 
    {
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
    } else 
    {
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
    }

    notificationBuilder.setContentTitle(notificationModel.getTitle())
            .setContentText(notificationModel.getMessage())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)
    {
        int importance = NotificationManager.IMPORTANCE_LOW;
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "NOTIFICATION_CHANNEL_NAME", importance);
        notificationChannel.enableLights(true);
        notificationChannel.setLightColor(Color.RED);
        notificationChannel.enableVibration(true);
        notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        assert notificationManager != null;
        notificationBuilder.setChannelId(NOTIFICATION_CHANNEL_ID);
        notificationManager.createNotificationChannel(notificationChannel);
    }

    assert notificationManager != null;
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
Johnstone answered 23/11, 2017 at 10:59 Comment(2)
Related question with better answer. Importantly, see comments under the accepted answer, explaining how to define @string/default_notification_channel_idin your strings.xml - otherwise, you are referring to a non-existent value.Sourpuss
Possible duplicate of Firebase: How to set default notification channel in Android app?Sourpuss
S
36

I know this is late but I hope this helps you or at least someone else. It has been answered before here.

Basically, you have the meta-data name wrong.
Instead of

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

it should be

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

UPDATE: Added missing quote

Seminal answered 14/5, 2018 at 22:49 Comment(2)
default_notification_channel_id is already set? or should set where?Quijano
@Quijano default_notification_channel_id set on res/values/strings.xml. So you can edit and set your channel_idScranton
I
9

Answer and tips for newer

The meta-data tag:

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

Is going inside the application tag on AndroidManifest.xml, example:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.domain.appname">

  <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_launcher" />

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

And there is a file called "app/src/main/res/values/strings.xml" where you need to add this line inside resources tag :

<string name="default_notification_channel_id">com.domain.appname.urgent</string>

The value "com.domain.appname.urgent" need to be the same as your default created channel.

strings.xml look like:

<?xml version='1.0' encoding='utf-8'?>
<resources>
    <string name="app_name">MyApp</string>
    <string name="title_activity_main">MyApp</string>
    <string name="package_name">com.domain.appname</string>
    <string name="custom_url_scheme">com.domain.appname</string>
    <string name="default_notification_channel_id">com.domain.appname.urgent</string>
</resources>
Intonation answered 9/8, 2021 at 7:29 Comment(0)
A
3

Ah!,you may be forget to add channel id on your manifest so check your manifest and add meta for channel id

 <meta-data
 android:name="com.google.firebase.messaging.default_notification_channel_id"
 android:value="@string/default_notification_channel_id"/> 
Artema answered 28/11, 2021 at 16:9 Comment(1)
Please add some explanation to your answer such that others can learn from itBukovina
T
2

I had the same problem as you. You had an incorrect meta name.

Instead of

android:name="com.google.firebase.messaging.default_notification_channel"

you should use

android:name="com.google.firebase.messaging.default_notification_channel_id"

the only different is the "_id"

Tolle answered 18/9, 2020 at 9:47 Comment(0)
B
0

I have the same issue in firebase_messaging: ^14.7.14

Adding below in AndroidManifest.xml works for me.

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="high_importance_channel" />
Bromism answered 6/2, 2024 at 5:2 Comment(0)
W
0

Note - this answer targets flutter users

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

Place this line directly under

<application> here </application>

tag instead of

<application>
  <activity> NOT HERE </activity>
</application>

full example :-

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:name="${applicationName}"
        android:usesCleartextTraffic="true"
        android:enableOnBackInvokedCallback="true"
        android:icon="@mipmap/launcher_icon">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
           
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme"
            />
           
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

          

        </activity>

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

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

</manifest>

After modifying any android specific file do run

flutter clean

and

flutter pub get

and then restart the app if not running already

Wasson answered 13/7, 2024 at 13:26 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.