A msg pops up: 'Error, could not load media' when trying to crop a jpg picked from Gallery on an Android AVD API Level 31

142 Views Asked by At

In my Android app, I just select a JPG from the Gallery through Intent.ACTION_PICK, then pass its URI to CROP intent. But, on an AVD(API Level 31), I got a pop-up message: 'Error, could not load media', then the crop feature failed to start.

In fact, that JPG file locates on Stoareg\Pictures folder. And in Files app, I found its original URI is 'content://com.android.providers.downloads.documents/document/msf%3A74'.

After calling Intent.ACTION_PICK, I got its URI. mImageCaptureUri = data.getData();

In LogCat, I Logger.D() the URI mImageCaptureUri. It's as below. content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F76/ORIGINAL/NONE/image%2Fjpeg/296819256

Q1: Why did this URI change? It seems to have a strange prefix.

Q2: Is this weird URI causing the startup cropping to fail?

Q3: What's even more surprising is, this app works well on an AVD of API Level 33, and the startup cropping function is completely normal.

So now, I'm curious to know, what's going on here?

1

There are 1 best solutions below

0
Johnson On

Thank you all. At last, I found that this issue resulted from the Intent.ACTION_PICK on API Level 31 AVD while it works fine on any other API Level AVDs. I changed to use Intent.ACTION_OPEN_DOCUMENT, and now it works fine on all API Level AVDs. Share with you all. Thanks again.