首页 > 解决方案 > AndroidManifest 中缺少默认通知通道元数据。Flutter 将使用默认值

问题描述

我正在使用 Firebase Messaging 版本 10.0.2 和 flutterLocalNotification 版本 6.0.0。每当我在我的应用程序处于后台时使用 firebase 消息运行通知时,我都会在控制台中不断收到此异常Missing Default Notification Channel metadata in AndroidManifest。即使我使用颤振 localNotification 插件创建了通知通道,也会使用默认值。虽然,当应用程序处于前台时,这非常有效这是我的 Manifest.xml 文件

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.app">
  <application
    android:label="app"
    android:icon="@mipmap/ic_launcher">
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        
        <meta-data
          android:name="io.flutter.embedding.android.SplashScreenDrawable"
          android:resource="@drawable/launch_background"
          />
        <meta-data
             android:name="com.google.firebase.messaging.default_notification_channel_id"
          android:value="app"/>
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>

这也是我创建通知通道的代码

 static final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
    FlutterLocalNotificationsPlugin();

  static void initialize() {
    final InitializationSettings initializationSettings =
      InitializationSettings(
        android: AndroidInitializationSettings("@mipmap/ic_launcher"));

  static void createChannelAndDisplay(RemoteMessage message) async {
    final id = DateTime.now().millisecondsSinceEpoch ~/ 1000;
    final NotificationDetails notificationDetails = NotificationDetails(
      android: AndroidNotificationDetails(
          "app", "app_channel", "my app channel",
          importance: Importance.max, priority: Priority.high));

  await flutterLocalNotificationsPlugin.show(
      id,
      message.notification!.title,
      message.notification!.body,
      notificationDetails,
     );

我怎么了?

标签: flutterpush-notificationfirebase-cloud-messaging

解决方案


推荐阅读