Implementation
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
LogManager().addLog("firebaseMessagingBackgroundHandler: ${message.data}", screen: runtimeType.toString());
math.Random rng = math.Random();
int tag = rng.nextInt(9999999);
// LogManager().addLog("receive push message on background: ${message.data}", screen: runtimeType.toString());
// LogManager().addLog("message.data", screen: runtimeType.toString());
await Firebase.initializeApp();
// LogManager().addLog("message.data", screen: runtimeType.toString());
// LogManager().addLog(message.data.toString(), screen: runtimeType.toString());
// print("message.data");
// print(message.data);
if (message.data != null) {
Map<String, dynamic> pinpointMessage = message.data;
pinpointMessage["pinpoint.notification.title"] = message.notification!.title!;
pinpointMessage["pinpoint.notification.body"] = message.notification!.body!;
if (flutterLocalNotificationsPlugin == null) {
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
}
if (pinpointMessage["pinpoint.notification.imageUrl"] != null && pinpointMessage["pinpoint.notification.imageIconUrl"] != null) {
log("h2");
return NotificationService().showBigPictureNotification(pinpointMessage);
} else if (pinpointMessage["pinpoint.notification.imageUrl"] != null) {
return NotificationService().showBigPictureNotificationHiddenLargeIcon(pinpointMessage);
} else {
flutterLocalNotificationsPlugin.show(
// pinpointMessage["pinpoint.campaign.campaign_id"].hashCode,
tag,
pinpointMessage["pinpoint.notification.title"],
pinpointMessage["pinpoint.notification.body"],
NotificationDetails(
android: AndroidNotificationDetails(
'high_importance_channel', // id
'High Importance Notifications', // title
channelDescription: 'This channel is used for important notifications.',
// description
importance: Importance.high,
icon: null, // android?.smallIcon,
tag: tag.toString(),
// other properties...
),
),
);
}
}
}