您的位置:首页 > 移动开发 > Android开发

android获取手机所有图片

2017-12-14 17:21 393 查看
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 Hash
4000
Map<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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: