Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass uri to another activity and convert it to image

Tags:

android

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 ));
like image 248
Moudiz Avatar asked Sep 19 '15 05:09

Moudiz


People also ask

How do I pass URI?

How do I pass a URI? private Uri imageUri; .... Intent intent = new Intent(this, GoogleActivity. class); intent.

What is an intent in Java?

An Intent is a messaging object you can use to request an action from another app component. Although intents facilitate communication between components in several ways, there are three fundamental use cases: Starting an activity. An Activity represents a single screen in an app.


1 Answers

Convert you URI to String while adding to Intent like given below

i.putExtra("imagePath", selectedImage.toString());

and in your NextActivity get the String and convert back to URI like ->

Intent intent = getIntent(); 
String image_path= intent.getStringExtra("imagePath"); 
Uri fileUri = Uri.parse(image_path) 
imageview.setImageURI(fileUri) 
like image 132
Satyen Udeshi Avatar answered Nov 10 '22 00:11

Satyen Udeshi