Skip to content

Commit

Permalink
fix: Fix the problem that the image cannot be automatically scanned a…
Browse files Browse the repository at this point in the history
…fter saving on Android
  • Loading branch information
doraemonkeys committed Dec 27, 2024
1 parent 54f5aa7 commit 8b77735
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions flutter/wind_send/lib/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import 'cnf.dart';
import 'protocol/protocol.dart';
import 'file_picker_service.dart';
import 'main.dart';
import 'package:media_scanner/media_scanner.dart';
// import 'package:flutter/services.dart' show rootBundle;

class Device {
late String targetDeviceName;
Expand Down Expand Up @@ -484,6 +486,9 @@ class Device {
filepath.join(AppConfigModel().imageSavePath, imageName);
await Directory(AppConfigModel().imageSavePath).create(recursive: true);
await File(filePath).writeAsBytes(respBody);
if (Platform.isAndroid) {
MediaScanner.loadMedia(path: filePath);
}
final clipboard = SystemClipboard.instance;
if (clipboard == null) {
return (null, <DownloadInfo>[], [filePath]);
Expand Down Expand Up @@ -636,6 +641,13 @@ class Device {
await writeFileToClipboard(clipboard, File(lastRealSavePath[0]));
}
}
if (Platform.isAndroid) {
String lastImagePath = lastRealSavePath
.lastWhere((element) => hasImageExtension(element), orElse: () => '');
if (lastImagePath.isNotEmpty) {
MediaScanner.loadMedia(path: lastImagePath);
}
}
return lastRealSavePath;
}

Expand Down
4 changes: 4 additions & 0 deletions flutter/wind_send/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ dependencies:
share_plus: ^10.1.3
fluttertoast: ^8.2.10
open_filex: ^4.6.0
media_scanner:
git:
url: https://github.com/mbfakourii/media_scanner
ref: support_gradle_8

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 8b77735

Please sign in to comment.