Flutter 当应用程序处于后台时,如何为颤振应用程序添加android通知频道id以修复通知

Flutter 当应用程序处于后台时,如何为颤振应用程序添加android通知频道id以修复通知,flutter,firebase-cloud-messaging,android-notifications,Flutter,Firebase Cloud Messaging,Android Notifications,在我的flatter应用程序中,onResume和onLunch的功能在android平台上不起作用,而在IOS上工作正常, 我在控制台上收到以下消息,而不是这些函数中的打印字符串: “W/FirebaseMessaging(24847):AndroidManifest中缺少默认通知通道元数据。将使用默认值。” onMessage功能工作正常,问题是应用程序在后台时 我的猜测是,它与android通知通道id有关,应该添加到android清单中 当我通过向AndroidManifest添加以下代

在我的flatter应用程序中,onResume和onLunch的功能在android平台上不起作用,而在IOS上工作正常, 我在控制台上收到以下消息,而不是这些函数中的打印字符串:

“W/FirebaseMessaging(24847):AndroidManifest中缺少默认通知通道元数据。将使用默认值。”

onMessage功能工作正常,问题是应用程序在后台时

我的猜测是,它与android通知通道id有关,应该添加到android清单中

当我通过向AndroidManifest添加以下代码将其添加到清单时,消息将更改为: (我在values中添加了一个strings.xml文件,并在其中定义了“default\u notification\u channel\u id”。)

“应用程序尚未创建AndroidManifest.xml中设置的通知通道。将使用默认值。”


在我的控制台中,我应该会收到我打印的onResume和OnRunch字符串,但我会收到以下消息:

“W/FirebaseMessaging(24847):AndroidManifest中缺少默认通知通道元数据。将使用默认值。”

“应用程序尚未创建AndroidManifest.xml中设置的通知通道。将使用默认值。”


您是否创建了
默认通知\u频道\u id

“W/FirebaseMessaging(24847):AndroidManifest中缺少默认通知通道元数据。将使用默认值。”


如果未在通知的有效负载中设置通道id,则会出现此警告。您应该首先创建一个通知通道,插件:可以创建和删除通知通道

首先,初始化插件:

Future<void> initializeLocalNotifications() async {
  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
  FlutterLocalNotificationsPlugin();
  // app_icon needs to be a added as a drawable resource to the
  // Android head project
  var initializationSettingsAndroid = AndroidInitializationSettings('app_icon');
  var initializationSettingsIOS = IOSInitializationSettings(
      onDidReceiveLocalNotification: onDidReceiveLocalNotification);
  var initializationSettings = InitializationSettings(
      initializationSettingsAndroid, initializationSettingsIOS);
  await flutterLocalNotificationsPlugin.initialize(initializationSettings,
      onSelectNotification: selectNotification);
}

如果您指的是firebase控制台中的通道id,那么是的,我尝试使用通道id发送通知,但仍然无法使用您在AndroidManifest.xml=>中已定义的默认id创建通道。如何执行此操作?您可以定义默认通知通道,如中所示。
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id"/>
Future<void> initializeLocalNotifications() async {
  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
  FlutterLocalNotificationsPlugin();
  // app_icon needs to be a added as a drawable resource to the
  // Android head project
  var initializationSettingsAndroid = AndroidInitializationSettings('app_icon');
  var initializationSettingsIOS = IOSInitializationSettings(
      onDidReceiveLocalNotification: onDidReceiveLocalNotification);
  var initializationSettings = InitializationSettings(
      initializationSettingsAndroid, initializationSettingsIOS);
  await flutterLocalNotificationsPlugin.initialize(initializationSettings,
      onSelectNotification: selectNotification);
}
Future<void> _createNotificationChannel(String id, String name,
    String description) async {
  final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
  var androidNotificationChannel = AndroidNotificationChannel(
    id,
    name,
    description,
  );
  await flutterLocalNotificationsPlugin
      .resolvePlatformSpecificImplementation<
      AndroidFlutterLocalNotificationsPlugin>()
      ?.createNotificationChannel(androidNotificationChannel);
}
    'notification': {
        'title': your_title,
        'body': your_body,
    },
    'android': {
        'notification': {
            'channel_id': your_channel_id,
        },
    },