下面是我的代码:
const AndroidNotificationChannel notificationChannel = AndroidNotificationChannel(
'high_importance_channel',
'high importance Notificaion',
'this channel is used for import notification',
importance: Importance.high,
playSound: true,
);
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
Future<void> firebaseBackgroundMessageHandler(RemoteMessage message) async {
await firebaseMessageHandler(message);
}
Future<void> firebaseForegroundMessageHandler(RemoteMessage message) async {
await firebaseMessageHandler(message);
}
Future<void> firebaseMessageHandler(RemoteMessage message) async {
await Firebase.initializeApp();
try {
flutterLocalNotificationsPlugin.show(
message.notification.hashCode,
message.data["title"].toString(),
message.data["body"].toString(),
NotificationDetails(
android: AndroidNotificationDetails(notificationChannel.id, notificationChannel.name, notificationChannel.description),
));
} catch (_err) {}
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(firebaseBackgroundMessageHandler);
FirebaseMessaging.onMessage.listen(firebaseForegroundMessageHandler);
//FirebaseMessaging.onMessageOpenedApp.listen(firebaseMessageHandler);
final AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('e_app');
final InitializationSettings initializationSettings = InitializationSettings(android: initializationSettingsAndroid);
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
await flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()?.createNotificationChannel(notificationChannel);
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(alert: true, badge: true, sound: true);
}
代码对于单个通知工作正常,但每当我向android发送多个通知时,它只在状态栏中显示最后一个通知。
谁能帮我一下如何使用flutter本地通知插件在状态栏中显示多个通知?
2条答案
按热度按时间hs1ihplo1#
如果你想对通知进行分组,flutter_local_notifications中有一个选项。为此,可以在代码中添加以下内容
for ios:threadIdentifier in IOSNotificationDetails
对于Android:groupChannelId,groupChannelName,groupChannelDescription,
你可以在这里的文档中找到这些:https://pub.dev/packages/flutter_local_notifications#displaying-a-notification,位于“分组通知”下。
基本上相同threadId或groupId下的通知都会被分组显示
oxiaedzo2#
flutter show通知id将是唯一的
Android通知json格式
这种格式的JSON是自动禁用FCM通知