Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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());
}
like image 674
jazzbpn Avatar asked Nov 23 '17 10:11

jazzbpn


2 Answers

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

like image 115
Simran Avatar answered Oct 22 '22 15:10

Simran


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"

like image 22
Jimmy Avatar answered Oct 22 '22 17:10

Jimmy