4

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??

xyz rety
  • 671
  • 2
  • 11
  • 22

5 Answers5

3

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");
zeroDivider
  • 1,050
  • 13
  • 29
2

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"));
Sabby
  • 403
  • 3
  • 15
0

when saving

String str = myUri.toString();
intent.putExtra("singleImage", uri);

and when loading

String str = getIntent().getStringExtra("singleImage");
Uri myUri = Uri.parse(str);

Hope it will help you :)

Neo
  • 3,546
  • 1
  • 24
  • 31
0

you can save data as String and parse uri from String

Alex Shutov
  • 3,217
  • 2
  • 13
  • 11
0

Try

intent.putExtra("singleImage", uri.toString());
Sathish Kumar J
  • 4,280
  • 1
  • 20
  • 48