点击通知时未启动应用程序?Flutter本地通知



我正在做一个项目,我使用Flutter本地通知来显示定期通知,我正试图弄清楚是否有办法不在点击通知时启动应用程序,例如,当用户点击通知时,它应该从通知面板中消失。

这是我迄今为止尝试过的代码,

初始化,

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下的close函数。

static final onNotifications = BehaviorSubject<String?>();

然后在选择通知时调用此命令。

onSelectNotification() => onNotifications.close();

相关内容

  • 没有找到相关文章

最新更新