How to send a uri
path of an image to another activity and convert it to image. I tried the below
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK && data != null && data.getData() != null) {
//file name
Uri selectedImage = data.getData();
Intent i = new Intent(this,
AddImage.class);
i.putExtra("imagePath", selectedImage);
startActivity(i);
and get it like this
String imagePath = getIntent().getStringExtra("imagePath");
imageview.setImageURI(Uri.parse(imagePath ));
To pass an image Uri to the next activity, you can just use
setData()
andgetData()
. There is no need to convert the Uri to anything.First Activity
Second Activity
to use the returned uir from the calling activity and then set it to a imageview you can do this
This is a workaround for refreshing an ImageButton, which tries to cache the previous image Uri. Passing null effectively resets it.
For converting the inputStream into a bitmap you could do this
and then call
to set it it a imageview, you could also check this link for an example
hope i could help
Convert you
URI
to String while adding toIntent
like given belowand in your
NextActivity
get theString
and convert back toURI
like ->in Next activity get that URI like this;
and to convert that Image_URI to Image use Below mentioned Code
First Activity
Second class