W / FirebaseMessaging: в AndroidManifest отсутствуют метаданные канала уведомлений по умолчанию. Будет использоваться значение по умолчанию

В нашем приложении теперь есть targetSdkVersion 26 (Android 8), и приложение использует push-уведомления FCM. Когда приложение находится в состоянии переднего плана, push-уведомление работает нормально. Проблема появляется при нажатии на уведомление, когда приложение не находится в состоянии переднего плана. Я только что добавил метаданные в манифест, но все равно получил ту же ошибку.

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());
}

comment
Связанный вопрос с лучшим ответом. Важно отметить, что см. Комментарии под принятым ответом, объясняющие, как определить @string/default_notification_channel_id в вашем strings.xml - в противном случае вы имеете в виду несуществующее значение.   -  person ToolmakerSteve    schedule 27.03.2019
comment
Возможный дубликат Firebase: как установить канал уведомлений по умолчанию в Приложение для Android?   -  person ToolmakerSteve    schedule 27.03.2019


Ответы (2)


Я знаю, что это поздно, но я надеюсь, что это поможет вам или, по крайней мере, кому-то еще. Ответ на него был дан перед здесь.

По сути, у вас неправильное имя метаданных.
Вместо

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

должно быть

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

ОБНОВЛЕНИЕ: добавлена ​​отсутствующая цитата

person Simran    schedule 14.05.2018
comment
default_notification_channel_id уже установлен? или надо ставить где? - person shinriyo; 24.08.2020
comment
@shinriyo default_notification_channel_id установлен в res / values ​​/ strings.xml. Итак, вы можете отредактировать и установить свой channel_id - person K.Amanov; 01.05.2021

У меня была такая же проблема, как и у вас. У вас неправильное мета-имя.

Вместо того

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

вы должны использовать

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

единственное отличие - это _id

person Jimmy    schedule 18.09.2020