2
我正在寻找一种方法来查找SD卡上的图像,或至少是相机拍摄的图像。Android:获取图像位置
理想的解决方案是获取图像的文件路径或URI的集合。我猜你可以通过MediaStore做到这一点,我只是无法弄清楚。
感谢
我正在寻找一种方法来查找SD卡上的图像,或至少是相机拍摄的图像。Android:获取图像位置
理想的解决方案是获取图像的文件路径或URI的集合。我猜你可以通过MediaStore做到这一点,我只是无法弄清楚。
感谢
寻找更多MediaStore的例子后,我来到了这一点,它能够完成任务。
protected ArrayList<Uri> GetImageList(boolean getThumbs)
{
ArrayList<Uri> images = new ArrayList<Uri>();
String columnType;
Uri contentType;
String[] columnNames;
if (getThumbs)
{
columnType = MediaStore.Images.Thumbnails._ID;
contentType = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI;
}
else
{
columnType = MediaStore.Images.Media._ID;
contentType = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
}
columnNames = new String[]{columnType};
Cursor cursor = managedQuery(contentType, columnNames, null, null, null);
int columnIndex = cursor.getColumnIndexOrThrow(columnType);
for(int i = 0; i < cursor.getCount(); i++)
{
cursor.moveToPosition(i);
int id = cursor.getInt(columnIndex);
images.add(Uri.withAppendedPath(contentType, "" + id));
}
return images;
}
它返回所有图像的Uri或SD卡上所有图像的缩略图的Uri。
最好是使用MediaStore.Images.Media.BUCKET_DISPLAY_NAME过滤掉照片,而不是读取uri – shem 2013-02-05 13:43:25