我与Android 2.1的工作,我想从相机意图的结果真实路径。 我读从ACTION_IMAGE_CAPTURE意图获取图像的路径 ,但它是为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();
}
}