首页 > 系统 > Android > 正文

Android获取系统相册里的全部图片

2019-11-06 09:41:27
字体:
来源:转载
供稿:网友

只有获取本地图片地址功能,未做压缩,请自行进行压缩处理

public static List<String> getSystemPhotoList(Context context) {    List<String> result = new ArrayList<String>();    Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;    ContentResolver contentResolver = context.getContentResolver();    Cursor cursor = contentResolver.query(uri, null, null, null, null);    if (cursor == null || cursor.getCount() <= 0) return null; // 没有图片    while (cursor.moveToNext()) {        int index = cursor                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);        String path = cursor.getString(index); // 文件地址        File file = new File(path);        if (file.exists()) {            result.add(path);            Log.i(TAG, path);        }    }    return result;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表