How To Use Login:pass@ Url In Glide On Android?
Trying Glide library for Android. It is necessary to download pictures and display it in the ImageView. If this type url http: //www.some.domen / storage / images / image.jpg all
Solution 1:
Based on https://stackoverflow.com/a/5137446/253468 I think this could be a workaround/solution (untested):
LazyHeaders auth = new LazyHeaders.Builder() // can be cached in a field and reused
.addHeader("Authorization", new BasicAuthorization(username, password))
.build();
Glide
.with(context)
.load(new GlideUrl(url, auth)) // GlideUrl is created anyway so there's no extra objects allocated
.into(imageView);
public class BasicAuthorization implements LazyHeaderFactory {
private final String username;
private final String password;
public BasicAuthorization(String username, String password) {
this.username = username;
this.password = password;
}
@Override public String buildHeader() {
return "Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP);
}
}
Post a Comment for "How To Use Login:pass@ Url In Glide On Android?"