Karim Varela
Karim Varela

Reputation: 7652

"Error, could not load media" when attempting to call Photos app crop intent sending Uri that points to files dir

What I'm attempting to do:

Select a photo from my Facebook photos and then send that photo to the native Photo editing experience (the Photos app)

Here are the steps I'm taking:

  1. Get url for photo from fb
  2. Use Picasso to fetch image url into Bitmap
  3. Store that Bitmap to a file on disk in my app specific /data/data/ dir
  4. Create a Uri from that file path
  5. Send that Uri as the data part of the implicit Intent for the "com.android.camera.action.CROP" action

I'm guessing the problem is that the Photos app doesn't have permission to access the file in my /data/data dir, but I'm curious if anyone can confirm that is indeed the problem and, if so, how you solved it. I'm guessing the solution is to save the file to the SD card instead so that the Photos app can access it?

Ok, here's some code ...

After I've written the Bitmap to file, I call this to get Uri

Uri pictureUri = Uri.fromFile(new File(path))

I then send that Uri to the crop intent like so

Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(pictureUri, "image/*");

And start Activity for Result

activity.startActivityForResult(intent, RequestCode.CROP_IMAGE);

Any feedback much appreciated!

Upvotes: 1

Views: 3761

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 200110

You are correct that sharing files often leads to permission problems, particular since READ_EXTERNAL_STORAGE is a dangerous permission on Android 6.0+ higher devices (requiring you to

Instead, you should follow the sharing files training and use FileProvider to create a Uri that other apps can read without the storage permissions (on your part or on the other app's part).

Upvotes: 2

Related Questions