直接获取所有照片的信息,而不是打开照片选择页面
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 
 |  private ArrayList<CategoryFile> queryCategoryFilesSync(FileType type) {ArrayList<CategoryFile> files = new ArrayList<>();
 Uri uri = MediaStore.Images.Media.getContentUri("external");
 if (uri != null) {
 String[] projection = new String[]{FileColumns._ID,
 FileColumns.DATA,
 FileColumns.SIZE,
 FileColumns.DATE_MODIFIED};
 Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
 if (cursor != null) {
 try {
 if (cursor.moveToFirst()) {
 final int pathIdx = cursor
 .getColumnIndex(FileColumns.DATA);
 final int sizeIdx = cursor
 .getColumnIndex(FileColumns.SIZE);
 final int modifyIdx = cursor
 .getColumnIndex(FileColumns.DATE_MODIFIED);
 do {
 String path = cursor.getString(pathIdx);
 CategoryFile file = new CategoryFile();
 file.mType = type;
 file.mPath = path;
 file.mParent = FileUtil.getPathFromFilepath(file.mPath);
 file.mName = FileUtil.getNameFromFilepath(file.mPath);
 file.mSize = cursor.getLong(sizeIdx);
 file.mLastModifyTime = cursor.getLong(modifyIdx);
 files.add(file);
 } while (cursor.moveToNext());
 }
 } catch (Exception e) {
 e.printStackTrace();
 } finally {
 cursor.close();
 }
 }
 }
 return files;
 }
 
 | 
其中CategoryFile为存储照片信息的Bean类
FileUtil类
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 
 | public class FileUtil {
 private static final char UNIX_SEPARATOR = '/';
 
 public static String getPathFromFilepath(String filepath) {
 if (!TextUtils.isEmpty(filepath)) {
 int pos = filepath.lastIndexOf(UNIX_SEPARATOR);
 if (pos != -1) {
 return filepath.substring(0, pos);
 }
 }
 return "";
 }
 
 public static String getNameFromFilepath(String filepath) {
 if (!TextUtils.isEmpty(filepath)) {
 int pos = filepath.lastIndexOf(UNIX_SEPARATOR);
 if (pos != -1) {
 return filepath.substring(pos + 1);
 }
 }
 return "";
 }
 }
 
 |