1

I create an intent to let the user pick an image from their gallery:

Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_PICK); startActivityForResult(intent, REQUEST_PICK_IMAGE); 

Then, after the user picks an image, I handle it here:

@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (requestCode == REQUEST_PICK_IMAGE) { final Uri uri = intent.getData(); Glide.with(context) .load(new File(uri.getPath())) .into(myImageView); } } 

The URI looks something like this:

content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F43/ORIGINAL/NONE/image%2Fpng/2098318161 

But it's not loading the image into the ImageView, and I don't know why.

1
  • You already got a perfect alternativ. But new File(uri.getPath()) did not work as the File class expects a file system path which is not delivered by getPath(). Just have a look at its value and you will see. Commented Oct 28, 2020 at 17:05

2 Answers 2

1

you can load it in to the imageView like this; myImageView.setImageURI(uri);

Sign up to request clarification or add additional context in comments.

2 Comments

Not really an option for me: stackoverflow.com/a/50220731/13770904
Why would not that be an option? You can put most code in a thread if that is the problem.
0

First thing, If you pass an Uri instance, In normal case it will start like this (file://) but in yours it doesn't have a correct schema . You can check how Uri, String and File models are loaded.

Second thing, If your using a testing device whose api level is >= 29 then you have to add a flag in manifest to access the storage.

requestLegacyExternalStorage=true 

Also check your result code if it's returning 0 or -1

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.