This question was originally asked for Android 1.6.
I am working on photos options in my app.
I have a button and an ImageView in my Activity. When I click
For some reasons, all of the answers in this thread, in onActivityResult()
try to post-process the received Uri
, like getting the real path of the image and then use BitmapFactory.decodeFile(path)
to get the Bitmap
.
This step is unnecessary. The ImageView
class has a method called setImageURI(uri)
. Pass your uri to it and you should be done.
Uri imageUri = data.getData();
imageView.setImageURI(imageUri);
For a complete working example you could take a look here: http://androidbitmaps.blogspot.com/2015/04/loading-images-in-android-part-iii-pick.html
PS:
Getting the Bitmap
in a separate variable would make sense in cases where the image to be loaded is too large to fit in memory, and a scale down operation is necessary to prevent OurOfMemoryError
, like shown in the @siamii answer.