【问题标题】:Flutter: How can I receive local notifications even if my app is closed?Flutter:即使我的应用已关闭,我如何才能收到本地通知?
【发布时间】:2018-04-24 16:45:02
【问题描述】:

我创建了一个 Flutter 应用程序,它每分钟接收一次信号,并在收到新信号时显示本地通知。打开应用程序时通知会很好地显示,但是当应用程序关闭时,我什么也没有收到。我尝试添加

    <receiver android:name=".notification.NotificationReceiver">
        <intent-filter>
            <action android:name="io.flutter.app.notification.RECEIVE"/>
            <action android:name="io.flutter.app.notification.DELETE" />
            <action android:name="io.flutter.app.notification.OPEN" /> 
        </intent-filter>
    </receiver>

在我的 AndroidManifest.xml 中,如用于 Android 的 issue 中所示,但它不起作用。

有办法用 Flutter 做到这一点吗?

【问题讨论】:

  • 您可能需要查看推送通知,因为它可以在应用程序不运行的情况下工作。

标签: notifications flutter


【解决方案1】:

如果是本地通知,请尝试flutter_local_notifications,代码来自sample example app 的sn-p。

  Future<void> _showNotification() async {
    var androidPlatformChannelSpecifics = AndroidNotificationDetails(
        'your channel id', 'your channel name', 'your channel description',
        importance: Importance.Max, priority: Priority.High, ticker: 'ticker');
    var iOSPlatformChannelSpecifics = IOSNotificationDetails();
    var platformChannelSpecifics = NotificationDetails(
        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.show(
        0, 'plain title', 'plain body', platformChannelSpecifics,
        payload: 'item x');
  }

它还可以选择安排通知,并根据单击的通知进行路由。

【讨论】:

    猜你喜欢
    • 2016-09-30
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 2019-05-03
    相关资源
    最近更新 更多