gpt4 book ai didi

java - 如何在 android gallery 中显示 10 分钟前拍摄的图像?

转载 作者:行者123 更新时间:2023-11-30 09:09:27 25 4
gpt4 key购买 nike

我想要允许用户从图库中选择图像的能力,但仅拍摄了图像,例如 10 分钟前(可能使用时间创建的元数据?)。

有如何打开图库和选择图像的示例:

Intent i = new Intent(Intent.ACTION_PICK, 
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);

但是,我只需要 10 分钟前拍摄的图像。

有没有人有想法?

最佳答案

我可能是错的,但我认为您不能通过使用 Intent.ACTION_PICK 直接实现此目的进入Gallery .我认为 MediaStore.Images.ImageColumns.DATE_TAKEN 有可能的方法和一个 Cursor如你所见in this answer .但是,我没有找到正确的方法。

然后,您可以采取一种解决方法:创建您自己的 Gallery进入你的应用程序。从Camera中选择所有图片文件夹、过滤它们并仅显示 x 分钟前放入您自己的文件夹 Gallery - 一个简单的 GridView .我认为这可能很容易做到:

  • 初始化 var小号:

    // FileArray
    private File[] aFile;
    // ArrayList
    private ArrayList<String> aImagePath = new ArrayList<String>();
  • 获取 DCIM Camera文件夹:

    File fPath = new File(Environment
    .getExternalStorageDirectory().toString() + "/DCIM/Camera");
  • 创建 FileArray并列出此文件夹中的文件:

    // use a FilenameFilter to have only the pictures in JPG
    aFile = fPath.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
    return name.toLowerCase().endsWith(".jpg");
    }
    });
  • 对于每个文件,获取最后修改日期并填充 ArrayList<String> :

    for(int i=0; i < aFile.length; i++) {
    long lastDate = aFile[i].lastModified(); // get last modified date
    long nowTime = nDate.getTime(); // get the current time to compare
    if(nowTime - lastDate < 600*1000) { // if less than 10 min
    String pathFile = aFile[i].getPath();
    aImagePath.add(pathFile); // populate the Array
    }
    }
  • 最后,反转Array将最新的图片放在第一位并显示它们:

    if(aImagePath.size() != 0) {
    Collections.reverse(aImagePath); // reverse the Array

    // Call an AsyncTask to create and retrieve each Bitmap
    // then, in onPostExecute(), populate the Adapter of the GridView
    } else {
    // No pictures taken 10 min ago!
    }

实际上,在AsyncTask , 你将不得不处理 Bitmap节省内存的选项...我在GridView中测试了这个进入 Fragment它运作良好。你可以找到我上面使用的引用资料:

也许有人有更好的解决方案,但上面的方法可以解决问题,只显示 10 分钟前用 Camera 拍摄的图像。的装置。希望对您有所帮助。

关于java - 如何在 android gallery 中显示 10 分钟前拍摄的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23048203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com