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

问题描述

我在我的应用中使用 Local Notifications,它在我的 iPhone 上运行良好,但是在我的 Android 模拟器上触发通知时,它没有在屏幕顶部显示通知,但是只有点:

enter image description here

通知实际上在通知中心显示良好:

enter image description here

我确保 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',);
  }

在这里遗漏了什么?

解决方法

您可以尝试使用此行将通知的重要性级别设置为最大值:

var i = [1,2,3,4,5];
var result = [];
var current = [];
i.reverse().forEach((num) => {
    current.unshift(num);
    result = current;
    current = [current];
})
console.log(JSON.stringify(result))

您将其添加到 AndroidNotificationDetails 类实例中。这将告诉 Android 操作系统通知对用户很重要,屏幕顶部的平视显示器(一个小弹出窗口)应该显示几秒钟。

我认为阅读Android notification documentation

后会解决您的问题