簡體   English   中英

如何在Android上保留圖像文件的最后修改日期?

[英]How can I persist last modified date of image file on android?

我正在開發一個可壓縮手機上所有圖像的android應用。

我使用Content Resolver來處理圖像。 但是,壓縮后更改了圖像的上次修改日期。 我想保留日期,因為在媒體掃描后(重新啟動后)圖像的順序已更改。

  • 使用Content Resolver更新圖像上的ContentValues無效,因為在媒體掃描后重建了圖像的上次修改日期。
  • 也可能無法調用“ File.setLastModified()”,因為此方法的有效性取決於SD卡的設置。

我需要持久方法來保持媒體掃描后的最后修改日期。 我假設Content Resolver可以提供方法的持久屬性。

你能幫我嗎?

我不確定這種邏輯是否會對您有所幫助。

try {
            InputStream is = new URL("your image url").openStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            Metadata metadata = ImageMetadataReader.readMetadata(bis,true);


    for (Directory directory : metadata.getDirectories()) {
    for (Tag tag : directory.getTags()) {
        System.out.println(tag);
    }
 }

            }
        catch (ImageProcessingException e){}
        catch (IOException e) {}

這是一個片段代碼,我們可以獲取創建日期,上次修改日期等信息,

修改EXIF信息有效! 謝謝! http://developer.android.com/reference/android/media/ExifInterface.html

ExifInterface exif=new ExifInterface(path);    
ExifInterface exifNew=new ExifInterface(newPath);
exifNew.setAttribute(ExifInterface.TAG_DATETIME, exif.getAttribute(ExifInterface.TAG_DATETIME));
exifNew.setAttribute(ExifInterface.TAG_ORIENTATION, exif.getAttribute(ExifInterface.TAG_ORIENTATION));
exifNew.saveAttributes();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM