颤动:即使我的应用程序关闭,我如何收到本地通知?

时间:2018-04-24 16:45:02

标签: notifications flutter

我创建了一个每分钟接收信号的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中,如此issue for Android中所示,但它无效。

有一种方法可以用Flutter做到这一点吗?

1 个答案:

答案 0 :(得分:1)

如果是本地通知,则尝试使用flutter_local_notifications中的代码段sample example app

  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');
  }

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

相关问题