Generally the on Activity Result gives us the path in the form :-
Uri imagePath = data.getData();
Content://media/external/images/media/1
To get the Real Path of the image or any other thing located in sdcard use this function.
Call this function with your URI path i.e of the type - Content://media/external/images/media/1
public String getRealPathFromURI(Uri contentURI){
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);
}
Now it will give you the real path i.e :-
/mnt/sdcard/peng.jpg
which is generally required.
Uri imagePath = data.getData();
Content://media/external/images/media/1
To get the Real Path of the image or any other thing located in sdcard use this function.
Call this function with your URI path i.e of the type - Content://media/external/images/media/1
public String getRealPathFromURI(Uri contentURI){
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);
}
Now it will give you the real path i.e :-
/mnt/sdcard/peng.jpg
which is generally required.
No comments:
Post a Comment