使用 flutter_local_notification 的 Flutter 推送通知在某些设备上显示白框如何解决此问题 大多数设备正确显示通知图标,但某些设备存在问题
res/drawable/aaaa_logo.png 是我添加的唯一图标
AndroidManifest.xml
这就是我处理这个问题的方式
static Future<void> showBigPictureNotificationHiddenLargeIcon(
String? title,
String? body,
String? orderID,
String image,
FlutterLocalNotificationsPlugin fln,
int? petId,
) async {
final String largeIconPath = await _downloadAndSaveFile(image, 'largeIcon');
final String bigPicturePath =
await _downloadAndSaveFile(image, 'bigPicture');
final BigPictureStyleInformation bigPictureStyleInformation =
BigPictureStyleInformation(
FilePathAndroidBitmap(bigPicturePath),
hideExpandedLargeIcon: true,
contentTitle: title,
htmlFormatContentTitle: true,
summaryText: body,
htmlFormatSummaryText: true,
);
final AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails(
'your channel id',
'your channel name',
largeIcon: FilePathAndroidBitmap(largeIconPath),
priority: Priority.max,
playSound: true,
styleInformation: bigPictureStyleInformation,
importance: Importance.max,
sound: const RawResourceAndroidNotificationSound('notification'),
);
final NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
await fln.show(0, title, body, platformChannelSpecifics,
payload: petId != null ? "petId:$petId" : orderID);
}
static Future<String> _downloadAndSaveFile(
String url, String fileName) async {
final Directory directory = await getApplicationDocumentsDirectory();
final String filePath = '${directory.path}/$fileName';
final Response response = await Dio()
.get(url, options: Options(responseType: ResponseType.bytes));
final File file = File(filePath);
await file.writeAsBytes(response.data);
return filePath;
}