4
votes

The Android app allows users to select a photo from their phone gallery which I save the URI to realm. I then retrieve this information and use Picasso to load it into the image view. For some reason the image is not loaded.

The URI is something like:

content://com.android.providers.media.documents/document/image%3A333180

I save it to realm using mCategory.icon = imageURI.toString() and then when I load it:

Picasso.with(getContext())
                .load(Uri.parse(mCategory.icon)) // mCategory.icon is a string 
                .resize(200, 200)
                .error(R.drawable.mountain) // default image to load
                .into(viewHolder.categoryIcon);
4
That Uri is not valid Uri for image path. - Enzokie

4 Answers

4
votes

The URI you got is a ContentProvider URI to show it with Picasso you try to do this:

    File file = new File(Uri.parse(mCategory.icon));
    Picasso.with(getContext())
            .load(file)  
            .resize(200, 200)
            .error(R.drawable.mountain) 
            .into(viewHolder.categoryIcon);

P.S: Though you can convert your ContentProveder path to Absolute path still it's better if you don't since Picasso support loading from the File..

2
votes

Use setLoggingEnabled(true) in picasso to check the log if there is any error message.

0
votes

Mentioned URI contains the encoded value of colon : i.e. %3A.

Either rename the source OR try Glide or some other library to serve the purpose.

0
votes

This is working perfectly with new version of Picasso 2.71828

Picasso.get()
       .load(imageUri)
       .placeholder(R.drawable.placeholder)
       .fit()
       .centerCrop()
       .into(viewHolder.categoryIcon);