【发布时间】:2014-09-05 10:56:06
【问题描述】:
我正在尝试获取 uri 并在解析为 MediaStore 图像的路径后。 我这样做是为了获取 uri:
Uri img_uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
使用此函数后,我将路径中的 uri 转换为:
public String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
但结果是我有媒体存储的路径,但有第一个元素。
例如:/mnt/sdcard/Pictures/Boat.jpg。但我只想要/mnt/sdcard/Pictures/。
请不要告诉我使用 join 和 split,因为这不是我想要的。
【问题讨论】:
标签: android path uri mediastore