我使用 android 2.1,我想从相机意图结果中获取真实路径。我从 ACTION_IMAGE_CAPTURE Intent 中读取了 Get Path of image但它适用于 android 2.2。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAMERA_RESULT)
{
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
imv.setImageBitmap(thumbnail);
Uri selectedImageUri = data.getData();
String path = getRealPathFromURI(selectedImageUri);
}
}
private String getRealPathFromURI(Uri contentUri)
{
try
{
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
catch (Exception e)
{
return contentUri.getPath();
}
}