I get a photo from the gallery.
Uri selectedImage = data.getData(); in this form
content://media/external/images/media/18 and how to get a real path with the name of the file?
In case you just need to cut the protocol (media / external / images / media / 18):
String path = selectedImage.uri.toString(); Real way:
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(); } } } The picture itself by URI:
InputStream is = getContentResolver().openInputStream(selectedImage); Bitmap bitmap = BitmapFactory.decodeStream(is); is.close(); Source: https://ru.stackoverflow.com/questions/413401/
All Articles