Is there a method to add a custom header to request when an image is downloaded? I can use volley or okhttp in Glide.
I tried adding a cookie to the cookiemanager in okhttpclient, but it didn't help.
Is there a method to debug request response in Glide?
To simply load an image to LinearLayout, we call the with() method of Glide class and pass the context, then we call the load() method, which contains the URL of the image to be downloaded and finally we call the into() method to display the downloaded image on our ImageView.
Placeholders are Drawables that are shown while a request is in progress.
Since 3.6.0 it's possible to set custom headers for each request:
GlideUrl glideUrl = new GlideUrl("url", new LazyHeaders.Builder() .addHeader("key1", "value") .addHeader("key2", new LazyHeaderFactory() { @Override public String buildHeader() { String expensiveAuthHeader = computeExpensiveAuthHeader(); return expensiveAuthHeader; } }) .build()); Glide....load(glideUrl)....;
Try this:
ImageView imgThumb = itemView.findViewById(R.id.image_thumb); GlideUrl url = new GlideUrl("https://your-url.com", new LazyHeaders.Builder() .addHeader("User-Agent", "your-user-agent") .build()); RequestOptions options = new RequestOptions() .diskCacheStrategy(DiskCacheStrategy.NONE); Glide.with(mContext).load(glideUrl) .transition(withCrossFade()) .thumbnail(0.5f) .apply(options) .into(imgThumb);
The Glide reference is:
implementation 'com.github.bumptech.glide:glide:4.6.1'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With