Picasso: Question: How to get the image by the URL synchronously?

Created on 25 Nov 2016  路  2Comments  路  Source: square/picasso

Hi,

I creating a MediaBrowser for Android Auto, so i need return a list of MediaItem with the Bitmap representing the Product image. I can do it automatically because Android dont let us modify the MediaItem, so i need get the image synchronously.

There is a method in Picasso to do it? Something like it:

Bitmap b = Picasso.with(this).getFromCache("http://....png.");

if (b != null) {
   // aeeee
}

Thanks.

Most helpful comment

After read the picasso source code i do it:

Bitmap bitmap = Picasso.with(this)
                        .load(productCoverImageURL)
                        .error(R.drawable.ic_image_not_available)
                        .placeholder(R.drawable.ic_image_not_available)
                        .networkPolicy(NetworkPolicy.OFFLINE)
                        .get();

But it cannot be executed on MainThead :(

All 2 comments

After read the picasso source code i do it:

Bitmap bitmap = Picasso.with(this)
                        .load(productCoverImageURL)
                        .error(R.drawable.ic_image_not_available)
                        .placeholder(R.drawable.ic_image_not_available)
                        .networkPolicy(NetworkPolicy.OFFLINE)
                        .get();

But it cannot be executed on MainThead :(

We have no way of querying only the cache synchronously because it uses much more complex keys than the simple URL. If you need an image lookup that can always be queried on the main thread I would recommend maintaining your own cache and only using Picasso to fill/update its entries.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JakeWharton picture JakeWharton  路  7Comments

paatz04 picture paatz04  路  6Comments

johnjeremih picture johnjeremih  路  4Comments

ivanmagdic picture ivanmagdic  路  3Comments

shekharsumn picture shekharsumn  路  3Comments