gpt4 book ai didi

android - 没有在通知点击时启动应用程序? Flutter 本地通知

转载 作者:行者123 更新时间:2023-12-04 23:43:02 25 4
gpt4 key购买 nike

我正在做一个项目,我使用 Flutter Local Notifications 来显示定期通知,
我试图弄清楚是否有办法在单击通知时不启动应用程序,例如,当用户单击通知时,它应该从通知面板中消失。
这是我到目前为止尝试的代码,
初始化,

var initializationSettingsAndroid =
AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIOS = IOSInitializationSettings();
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
_notificationPlugin = FlutterLocalNotificationsPlugin();
_notificationPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);

呼唤,
Future getPeriodicNoification() async {
print("hello");
// Show a notification every minute with the first appearance happening a minute after invoking the method
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'your channel id',
'your channel name',
'your channel description',
importance: Importance.Max,
priority: Priority.High,
);
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await _notificationPlugin.periodicallyShow(0, 'repeating title',
'repeating body', RepeatInterval.EveryMinute, platformChannelSpecifics);
}
回调函数(点击通知)
  Future onSelectNotification(String payload) async {
ThisisAnAsyncFunction();
}
请帮忙。

最佳答案

您可以使用添加有效负载时使用的 BehaviourSubject 下的关闭函数。

static final onNotifications = BehaviorSubject<String?>();
然后在选择通知时调用它。
onSelectNotification() => onNotifications.close();

关于android - 没有在通知点击时启动应用程序? Flutter 本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63427879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com