【发布时间】:2018-04-05 22:18:04
【问题描述】:
我有一个函数可以返回手机上所有图像的路径,但我只希望它返回相机拍摄的图像。这是函数:
public String[] getPath(){
final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
final String orderBy = MediaStore.Images.Media._ID;
//Stores all the images from the gallery in Cursor
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy);
//Total number of images
int count = cursor.getCount();
//Create an array to store path to all the images
String[] arrPath = new String[count];
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
//Store the path of the image
arrPath[i]= cursor.getString(dataColumnIndex);
Log.i("PATH", arrPath[i]);
}
cursor.close();
return arrPath;
}
为了只获取存储在 /DCIM/CAMERA 中的路径,我需要进行哪些更改?
【问题讨论】:
-
获取Android设备的所有相机图像列表,您可以通过此链接:stackoverflow.com/questions/4484158/…