以下代码将返回SD card
中的所有图片。但是,我需要修改它,以便它只显示其他文件夹中的图像。
Uri mImageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
ContentResolver mContentResolver = mContext.getContentResolver();
Cursor mCursor = mContentResolver.query(mImageUri, null, null, null, null);
我试过这个:
String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/Testing/";
Uri uri = Uri.parse(path);
Cursor mCursor = mContentResolver.query(Uri, null, null, null, null);
我收到了一个错误。任何帮助将不胜感激。
答案 0 :(得分:2)
Uri mImageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
// field data which u need
final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_ADDED};
Cursor mCursor = mContentResolver.query(mImageUri, columns, MediaStore.Images.Media.DATA + " like ? ",new String[] {"%/YourFolderName/%"}, null);
答案 1 :(得分:0)
ArrayList<String> fileNames =null
File path =
File(getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).path,
"Your Folder Name")
if (path.exists()) {
fileNames = path.getList() //you may need to to adjust the Data type of fileNames
}
因此,现在您有了图像路径列表,可以使用回收站视图适配器将其传递到回收站视图。