简体   繁体   English

Flutter 本地通知仅在 Android 上显示点

[英]Flutter Local Notification only showing dot on Android

I am using Local Notifications for my app and it is working fine on my iPhone but when firing a Notification on my Android Simulator it is not showing the Notification on top of the screen but only the dot:我正在为我的应用程序使用本地通知,它在我的 iPhone 上运行良好,但是在我的Android 模拟器上触发通知时,它没有在屏幕顶部显示通知,而只显示点:

在此处输入图像描述

The Notification actually appears fine in the Notification Center:通知实际上在通知中心看起来很好:

在此处输入图像描述

I am making sure to init and I a calling instantNotification which looks like this:我确保init并调用instantNotification ,如下所示:

  Future initialize() async {
    FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
        FlutterLocalNotificationsPlugin();

    AndroidInitializationSettings androidInitializationSettings =
        AndroidInitializationSettings('app_icon');

    IOSInitializationSettings iosInitializationSettings =
        IOSInitializationSettings();

    final InitializationSettings initializationSettings =
        InitializationSettings(
            android: androidInitializationSettings,
            iOS: iosInitializationSettings);

    await flutterLocalNotificationsPlugin.initialize(initializationSettings);
  }

  //Instant Notifications
  Future instantNofitication() async {
    var android = AndroidNotificationDetails('id', 'channel', 'description');

    var ios = IOSNotificationDetails();

    var platform = new NotificationDetails(android: android, iOS: ios);

    await _flutterLocalNotificationsPlugin.show(
      0,
      'Demo instant notification',
      'Tap to do something',
      platform,
      payload: 'Welcome to demo app',
    );
  }

What am I missing here?我在这里想念什么?

You can try setting the importance level of the notification to a maximum with this line:您可以尝试使用此行将通知的重要性级别设置为最大值:

importance: Importance.max

which you add to the AndroidNotificationDetails class instance.您将其添加到 AndroidNotificationDetails class 实例。 This will tell to an Android OS that notification is important for the user and a heads-up display (a little popup) on top of the screen should be displayed for a few seconds.这将告诉 Android 操作系统通知对用户很重要,并且屏幕顶部的平视显示(一个小弹出窗口)应该显示几秒钟。

I think that will solve your problem after reading an Android notification documentation我认为这将在阅读Android 通知文档后解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM