Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get data from intent in the form of uri?

Tags:

android

i have uri type data and i put data in intent using putExtra() but i have no idea how i get data in the uri from.

else if(requestCode==2){

           if (data != null) {
                   Uri uri = data.getData();

                   Intent intent = new Intent(getBaseContext(),BackUp_Main.class);
                   intent.putExtra("singleImage", uri);
                   startActivity(intent);

               }
}

how can i get uri data in the from of uri??

like image 428
xyz rety Avatar asked Oct 17 '25 02:10

xyz rety


2 Answers

You can parse and get Uri like this:

// Add an Uri instance to an Intent
intent.putExtra("imageUri", uri);

Then, when you need it, just get it back this way:

// Get an Uri from an Intent
Uri uri = intent.getParcelableExtra("imageUri");
like image 68
chitra Sathwara Avatar answered Oct 18 '25 15:10

chitra Sathwara


You can convert a uri to String as follows:-

intent.putExtra("singleImage", uri.toString());

and then while getting intent convert String to uri back

Uri myUri = Uri.parse(extras.getString("singleImage"));
like image 33
Sabby Avatar answered Oct 18 '25 15:10

Sabby