square / picasso

A powerful image downloading and caching library for Android
https://square.github.io/picasso/
Apache License 2.0
18.71k stars 3.97k forks source link

Uri content:// can not be loaded. #1692

Open Murtowski opened 6 years ago

Murtowski commented 6 years ago

Hey, I have trouble with displaying pictures from gallery on Samsung Devices. compile 'com.squareup.picasso:picasso:2.5.2'

However pictures of just taken photos form camera may be displayed (uri cames from camera)

1.Before all I give Application READ/WRITE_EXTERNAL_STORAGE permissions. 2.I create photo file using:

val mediaStorageDir = File(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_PICTURES), "ApplicationFolder")
  1. and I return picture using MediaScannerConnectionClient that gives me Uri in form of content:// instead of file:// Logs

    Created new uri:content://media/external/images/media/957
    for file: file:///storage/emulated/0/Pictures/ApplicationFolder/someName_25.10.2017-12%3A11%3A48.jpg
  2. I receive Uri in onActivityResult data.getData()

  3. Images from Camera are being displayed Uri from camera either gallery:content://media/external/images/media/957

    mImageView.post {      
    Picasso.with(mContext)
                .load(mUri)
                .placeholder(R.drawable.ic_loading_animated)
                .fit()
                .centerCrop() 
                .into(mImageView)

    But images from Gallery are not. Uri from camera either gallery:content://com.android.providers.media.documents/document/image%3A957

The only way to display them is to use

val inputStream = contentResolver.openInputStream(photoUri)
 val bitmap = BitmapFactory.decodeStream(inputStream)
pv_preview_picture.setImageBitmap(bitmap)

then all pictures display well, but I don't take adavantages of Picasso .fit() placeHolder() and so on and i disapointed of this solution

Summary: I don't know where is the problem. It's a problem of Piccasso, permission or Samsung. On my Nexus 6p i have no issue, but on Samsung i do.

UPDATE Finally I came accross two solution

taking bitmap from contentResolver.inputStream(uri) or imageView.setImageURI(uri)

but Picasso still not displaying pictures stackoverflow https://stackoverflow.com/questions/46930348/picasso-unable-to-display-image-from-gallery

CoolMind commented 6 years ago

Same problem on Huawei CUN-U29 running Android 5.1. It loads images from camera, also can show images from gallery, but when trying to write:

Picasso.with(getContext()).load(uri).centerCrop().resize(width, height).into(image);

it shows empty space.

On Meizu U20 (Android 6.0) it also doesn't show an image from camera (when centerCrop and resize).

UPDATE After many experimets, probably resizing during loading to a smaller size, both devices started to show an image in centerCrop.

ag2s20150909 commented 6 years ago

me too

antonshkurenko commented 6 years ago

I can confirm this too. Uris which come from "android.intent.action.SEND_MULTIPLE" can't be viewed on some devices like (lg x power 2, Android 7.0, photos are ~2.7-3 MB each).

m2kk commented 6 years ago

same here - any infos needed, please write, but i think it's 100% reproducible

deva56 commented 3 years ago

Huawei honor 9 lite, android 9. 2021 and still having these problems :/

martppa commented 3 years ago

Same issue with Huawei P30 Pro and Huawei Mate 40 Pro