【发布时间】:2022-07-24 19:47:49
【问题描述】:
我正在使用 firebase_messaging 和 flutter_local_notifications 进行通知,并且我能够在本地(前台)通知的情况下显示一个大图标,但我似乎没有找到一种方法在应用程序时显示相同的大图标是背景。
【问题讨论】:
标签: flutter push-notification firebase-cloud-messaging
我正在使用 firebase_messaging 和 flutter_local_notifications 进行通知,并且我能够在本地(前台)通知的情况下显示一个大图标,但我似乎没有找到一种方法在应用程序时显示相同的大图标是背景。
【问题讨论】:
标签: flutter push-notification firebase-cloud-messaging
使用 largeIcon 的更好方法是在发送通知时在通知负载中使用 image 属性:
const payload = {
notification: {
title: 'title',
body: 'description',
image: 'large_icon_url',
sound : "default"
},
};
【讨论】:
此代码可帮助您接收通知并在您的应用中使用:
void initMessaging() {
var androiInit = AndroidInitializationSettings(‘@mipmap/ic_launcher’);//for logo
var iosInit = IOSInitializationSettings();
var initSetting=InitializationSettings(android: androiInit,iOS:
iosInit);
fltNotification = FlutterLocalNotificationsPlugin();
fltNotification.initialize(initSetting);
var androidDetails =
AndroidNotificationDetails(‘1’, ‘channelName’, ‘channel
Description’);
var iosDetails = IOSNotificationDetails();
var generalNotificationDetails =
NotificationDetails(android: androidDetails, iOS: iosDetails);
FirebaseMessaging.onMessage.listen((RemoteMessage message) { RemoteNotification notification=message.notification;
AndroidNotification android=message.notification?.android;
if(notification!=null && android!=null){
fltNotification.show(
notification.hashCode, notification.title, notification.
body, generalNotificationDetails);
}
});
}
如果您有任何困难,请查看这篇文章:Flutter Push Notification Medium。 谢谢。
【讨论】: