Android cannot load image from URI using Picasso

androidpicasso

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);

Best Answer

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..