Android cannot load image from URI using Picasso

The Android app allows users to select a photo from their phone gallery, in which I save the URIs in the area. Then I extract this information and use Picasso to load it into the image. For some reason, the image does not load.

The URI looks something like this:

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

I save it in an area using mCategory.icon = imageURI.toString(), and then on boot:

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
source share
3 answers

The URI you received is a URI ContentProviderto show it with Picasso, you are trying 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: ContentProveder Absolute, , , Picasso .

+3

setLoggingEnabled(true) picasso, , .

+1

Said URI contains the encoded colon value :, i.e.% 3A.

Rename the source OR try Glide or some other library to complete this task.

0
source

Source: https://habr.com/ru/post/1674442/


All Articles