路径与所有图像的Andr​​oid文件夹 [英] Path to Android folder with all images

查看:122
本文介绍了路径与所有图像的Andr​​oid文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个功能从设备的最新保存的图像加载到一个应用程序。
目前我使用此路径 DCIM /摄像机/ ,但只存储相机拍摄的图像。是否有存储的所有图像文件夹? (截图,图片来自网络或相机胶卷保存)

I'm trying to build a feature to load the latest saved image from the device into an app. Currently I'm using this path DCIM/Camera/ but it only stores camera taken images. Is there a folder that stores all images? (screenshots, images saved from the web or camera roll)

推荐答案

相反在文件夹中的图像搜索中,你可以让系统照顾你们。

Instead of searching in in folders for the images, you can let the system take care of that for you.

Android的大多数指标在它自己和提供的内容提供商来查询这些数据库。

Android indexes most media-data (images, music, etc) on it's own and offers Content Providers to query these databases.

你的目的,你可以使用 MediaStore.Images.Media -provider

For your purposes, you can use the MediaStore.Images.Media-provider.

public List<String> getImagePaths(Context context) {
    // The list of columns we're interested in:
    String[] columns = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_ADDED};

    final Cursor cursor = context.getContentResolver().
            query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, // Specify the provider
                    columns, // The columns we're interested in
                    null, // A WHERE-filter query
                    null, // The arguments for the filter-query
                    MediaStore.Images.Media.DATE_ADDED + " DESC" // Order the results, newest first
            );

    List<String> result = new ArrayList<String>(cursor.getCount());

    if (cursor.moveToFirst()) {
        final int image_path_col = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        do {
            result.add(cursor.getString(image_path_col));
        } while (cursor.moveToNext());
    }
    cursor.close();

    return result;
}

的方法,将返回当前由MediaStore与最新的第一索引的所有图像的图像路径​​的列表。你需要在 android.permission.READ_EXTERNAL_STORAG​​E -permission这个工作!

The method will return a list of the image-paths of all images that are currently indexed by the MediaStore with the latest first. You'll need the android.permission.READ_EXTERNAL_STORAGE-permission for this to work!

这篇关于路径与所有图像的Andr​​oid文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆