Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug report] Saving image on android shows different DateTime then of original meta data #1246

Open
priyanshu-simformsolutions opened this issue Dec 16, 2024 · 6 comments

Comments

@priyanshu-simformsolutions

Version

3.6.2

Platforms

Android

Device Model

All

flutter info

[✓] Flutter (Channel stable, 3.22.2, on macOS 14.3.1 23D60 darwin-arm64,
    locale en-IN)
    • Flutter version 3.22.2 on channel stable at
      /Users/{MY_PATH}/fvm/versions/3.22.2
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (6 months ago), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version
    34.0.0)
    • Android SDK at /Users/{MY_PATH}/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.10+0-17.0.10b1087.21-11572160)

[✓] Connected device (4 available)
    • Pixel 6a (mobile) • android-arm64
      • Android 14 (API 34)

[✓] Network resources
    • All expected network resources are available.

• No issues found!

How to reproduce?

First of all, this is an amazing package for media management! Kudos to the contributors and maintainers!

I noticed an issue when saving images using PhotoManager.editor.saveImage() on Android. The saved image gets the current DateTime as its information. However, when I fetch the metadata of the same image later, it still contains the old DateTime.

This creates confusion because the gallery displays the image with the DateTime of when it was saved (current date and time). For example:

I save an image with DateTime metadata as 12 Jan, 2024.
After saving, the gallery shows the image with the date 16 Dec, 2024 (today).
But when I read the metadata, it still shows the old date, 12 Jan, 2024.
This behavior is inconsistent compared to iOS, where saving an image with DateTime metadata retains the original DateTime. The gallery also shows the image in the correct position based on that metadata.

Expected Result:

I want the option to save the image with its original DateTime metadata intact.
Alternatively, there could be an option to set the DateTime explicitly when saving the image.
Could you please clarify why this happens on Android or suggest a way to ensure the metadata and gallery display are consistent?

Thank you for your efforts!

Logs

No response

Example code (optional)

final imageEntity = await PhotoManager.editor.saveImage(
    byteData,
    filename: '$fileId.$mimeType',
);

Contact

No response

@fluttercandies-dev
Copy link

AI Summary: The user reports that on Android, saving an image with PhotoManager.editor.saveImage() updates the gallery display time to the current time, but the file's metadata retains the original date and time, unlike on iOS. They request the ability to either preserve the original DateTime or explicitly set it during saving.

@AlexV525
Copy link
Member

Could you provide the code you are using to read the metadata?

Dates in metadata and the MediaStore (which is how Android manages media) are different concepts. We read dates from MediaStore instead of the metadata.

There are a couple of improvement paths I could imagine to cover the case:

  1. When saving images, read their dates from the metadata instead of the current time.
  2. Allow users to define an explicit creation date to overwrite with the MediaStore.
  3. Modify the metadata with the given parameter.

These paths require extra investigation since the ability could be platform-specific.

@priyanshu-simformsolutions
Copy link
Author

priyanshu-simformsolutions commented Dec 16, 2024

Thank you for the response!
I used the Exif package to read metadata.

Once a File is converted into Uint8List, you can read the metadata using the following code:


  if (data.isEmpty) {
    print("No EXIF information found");
    return;
  }
  
  // Print metadata
  data.forEach((tag, value) {
    print("$tag: $value");
  });

@AlexV525
Copy link
Member

I don't know if there is an efficient way to overwrite the Exif date in the image bytes.

@priyanshu-simformsolutions
Copy link
Author

Not sure if this helps, but i just found an way to write and read exif data of an image.
Please look into this if something can be done

@priyanshu-simformsolutions
Copy link
Author

Exif read

Forgot to mention link here it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants