John
John

Reputation: 4981

Android Glide download before display

I'm using Glide and I want to know if it's possible to download all images without display them to fill the cache to display them later ? I tried this but the images are not downloaded :

for (String url: urls) {
    Glide.with(getBaseContext()).load(url);
    Log.v("Download", "processing");
}

Can you help me ?

Upvotes: 2

Views: 6171

Answers (3)

yoAlex5
yoAlex5

Reputation: 34185

Glide version 4.6.1

RequestOptions requestOptions = new RequestOptions().priority(Priority.IMMEDIATE);

Glide.with(appContext)
        .download(model)
        .apply(requestOptions)
        .submit();

Upvotes: 0

John
John

Reputation: 4981

I solved my problem we can use this to download the images :

Glide
   .with( context )
   .load( "http://futurestud.io/icon.png" )
   .downloadOnly(2000, 2000);

And to get and display the images in the cache, we should use the same url and add the diskCacheStrategy parameter like this :

Glide.with(context)
    .load( "http://futurestud.io/icon.png" )
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .into(imageView);

Upvotes: 7

Febi M Felix
Febi M Felix

Reputation: 2839

You can use asBitmap method in Glide to do the same.

Glide.with(this).
        load(url).
        asBitmap().
        into(100, 100). // Width and height
        get();

Upvotes: 0

Related Questions