If anyone trying to do this with Kotlin then here it is...
//variables
private lateinit var addImage: ImageView // set the id of your ImageView
private lateinit var imageUri: Uri
//open gallery to select an image
val gallery = Intent()
gallery.type = "image/*"
gallery.action = Intent.ACTION_GET_CONTENT
startActivityForResult(Intent.createChooser(gallery, "Select picture"), PICK_IMAGE)
//next
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == PICK_IMAGE && resultCode == RESULT_OK) {
imageUri = data?.data!!
try {
Picasso.get()
.load(imageUri)
.into(addImage)
} catch (e: Throwable) {
e.printStackTrace()
}
}
}
That's all you need.