android获取手机所有图片

来源:互联网 发布:简易流程图制作软件 编辑:程序博客网 时间:2024/05/01 22:28
    public ImageFilesBean returnImageFiles() {        List<String> parentsPthe = new ArrayList<>();        HashMap<String, String> pathMap = new HashMap<>();        Cursor cursor = getContentResolver().query(                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null);        while (cursor.moveToNext()) {            //获取其他图片信息//            String fileName = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));            String filePath = cursor.getString(cursor                    .getColumnIndex(MediaStore.Images.Media.DATA));            String parentName = new File(filePath).getParentFile().getAbsolutePath();            if (!parentsPthe.contains(parentName)) {                parentsPthe.add(parentName);                pathMap.put(parentName, filePath);            }        }        cursor.close();        return ImageFilesBean.returnBean(parentsPthe, pathMap);    }
package beini.com.ddd;import java.util.ArrayList;import java.util.HashMap;import java.util.List;public class ImageFilesBean {    private List<String> parentsPthe = new ArrayList<>();    private HashMap<String, String> pathMap = new HashMap<>();    public List<String> getParentsPthe() {        return parentsPthe;    }    public ImageFilesBean setParentsPthe(List<String> parentsPthe) {        this.parentsPthe = parentsPthe;        return this;    }    public HashMap<String, String> getPathMap() {        return pathMap;    }    public ImageFilesBean setPathMap(HashMap<String, String> pathMap) {        this.pathMap = pathMap;        return this;    }    public static ImageFilesBean returnBean(List<String> parentsPthe, HashMap<String, String> pathMap) {        return new ImageFilesBean().setParentsPthe(parentsPthe).setPathMap(pathMap);    }}

原创粉丝点击