gpt4 book ai didi

android - flutter_local_notifications 分组通知不起作用

转载 作者:行者123 更新时间:2023-12-04 23:50:03 31 4
gpt4 key购买 nike

我是 flutter 的新手我已经厌倦了对来自 Firebase Push Notification 的通知进行分组.我正在使用 flutter_local_notification用于在通知栏中显示通知的插件。

我为每个通知获得不同的标签。所以我使用了这个插件的分组功能来分组通知。

但它似乎仍然无法正常工作,它在通知栏中收到多个通知。任何帮助,将不胜感激。正如他们的文件所说,我在 24 级以上的 api 级别上尝试了这个。

我试过的示例代码如下。

String groupKey = 'com.android.example.WORK_EMAIL';

String groupChannelId = 'grouped channel id';

String groupChannelName = 'grouped channel name';

String groupChannelDescription = 'grouped channel description';

AndroidNotificationDetails firstNotificationAndroidSpecifics =
new AndroidNotificationDetails(
groupChannelId, groupChannelName, groupChannelDescription,
importance: Importance.Max,
priority: Priority.High,
groupKey: groupKey);

NotificationDetails firstNotificationPlatformSpecifics =
new NotificationDetails(firstNotificationAndroidSpecifics, null);

await flutterLocalNotificationsPlugin.show(1, 'Alex Faarborg',
'You will not believe...', firstNotificationPlatformSpecifics);

AndroidNotificationDetails secondNotificationAndroidSpecifics =
new AndroidNotificationDetails(
groupChannelId, groupChannelName, groupChannelDescription,
importance: Importance.Max,
priority: Priority.High,
groupKey: groupKey);

NotificationDetails secondNotificationPlatformSpecifics =
new NotificationDetails(secondNotificationAndroidSpecifics, null);

await flutterLocalNotificationsPlugin.show(
2,
'Jeff Chang',
'Please join us to celebrate the...',
secondNotificationPlatformSpecifics);

最佳答案

经过大量修补,下面的解决方案对我有用。您只需要setAsGroupSummary: true只到第一次通知。我的 AndroidNotificationDetails 的实现如下(我使用BigTextStyleInformation顺便说一句):

AndroidNotificationDetails _androidDetails(_NotificationType type, bool isGroupContainer) =>
AndroidNotificationDetails(
_NotificationPreference.GROUP_CHANNEL_ID,
_NotificationPreference.GROUP_CHANNEL_NAME,
_NotificationPreference.GROUP_CHANNEL_DESCRIPTION,
groupKey: _NotificationPreference.GROUP_CHANNEL,
icon: _NotificationPreference.APP_ICON,
priority: Priority.high,
importance: Importance.max,
setAsGroupSummary: isGroupContainer,
styleInformation: BigTextStyleInformation(type.getDetails.body,
contentTitle: type.getDetails.title));

NotificationDetails _flutterNotificationDetails(_NotificationType type, bool isGroupContainer) =>
NotificationDetails(android: _androidDetails(type, isGroupContainer), iOS: _iosDetails);
所以要在一个组中显示多个通知:
  @override
Future<void> showNotification() async {
await plugin.show(0, '', '',
_flutterNotificationDetails(_NotificationType.Container,true), payload: '1');
await plugin.show(_NotificationType.Type1.getDetails.id, _NotificationType.Type1.getDetails.title, _NotificationType.Type1.getDetails.body,
_flutterNotificationDetails(_NotificationType.Type1,false));
await plugin.show(_NotificationType.Type2.getDetails.id, _NotificationType.Type2.getDetails.title, _NotificationType.Type2.getDetails.body,
_flutterNotificationDetails(_NotificationType.Type2,false));
}
这将显示一个包含 2 个 child 的组通知。

关于android - flutter_local_notifications 分组通知不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56054269/

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