Android id不是url的滑动图像缓存
我在Android应用程序中工作,该应用程序从AmazonS3加载图像。 图像URL随令牌和到期密钥随机更改。因此,我无法缓存图像滑动 有任何方法可以将滑动缓存键设置为任何静态ID(如图像ID)而不是url 我附加了代码片段以从AWS加载图像Android id不是url的滑动图像缓存,android,android-glide,image-caching,Android,Android Glide,Image Caching,我在Android应用程序中工作,该应用程序从AmazonS3加载图像。 图像URL随令牌和到期密钥随机更改。因此,我无法缓存图像滑动 有任何方法可以将滑动缓存键设置为任何静态ID(如图像ID)而不是url 我附加了代码片段以从AWS加载图像 Glide.with(remoteGalleryAct).load(photoFinalImageURL) .signature(new StringSignature(getImageUrl(photoFinalImage
Glide.with(remoteGalleryAct).load(photoFinalImageURL)
.signature(new StringSignature(getImageUrl(photoFinalImageURL)))// remove AWS keys
.error(defaultNoImageDrawable)
.placeholder(defaultNoImageDrawable)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(new ImageViewTarget<GlideDrawable>(photoHolder.photo) {
@Override
protected void setResource(GlideDrawable resource) {
}
@Override
public void onResourceReady(final GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
//super.onResourceReady(resource, glideAnimation);
view.setImageDrawable(resource);
}
});
Glide.with(remoteGalleryAct.load)(photoFinalImageURL)
.signature(新建StringSignature(getImageUrl(photoFinalImageURL))//删除AWS密钥
.错误(defaultNoImageDrawable)
.占位符(默认为可绘制)
.dontAnimate()
.diskCacheStrategy(diskCacheStrategy.SOURCE)
.into(新的ImageViewTarget(photoHolder.photo){
@凌驾
受保护的void setResource(可提取资源){
}
@凌驾
public void onResourceReady(最终GlideDrawable资源,GlideAnimation重写GlideUrl类的getCacheKey()方法。此方法设置用于缓存图像的键
以下是如何做到这一点:
//Create a custom class and override the method to remove authentication header from the S3 image url
public class GlideUrlCustomCacheKey extends GlideUrl {
public GlideUrlCustomCacheKey(String url) {
super(url);
}
public GlideUrlCustomCacheKey(String url, Headers headers) {
super(url, headers);
}
public GlideUrlCustomCacheKey(URL url) {
super(url);
}
public GlideUrlCustomCacheKey(URL url, Headers headers) {
super(url, headers);
}
@Override
public String getCacheKey() {
String url = toStringUrl();
if (url.contains("?")) {
return url.substring(0, url.lastIndexOf("?"));
} else {
return url;
}
}
}
使用从此类获得的URL设置imageView:
Glide.with(context).load(new GlideUrlCustomCacheKey(buzzUrl)).into(imageView);
请在此上传您的代码抱歉,我附加了我的代码以从AWS S3加载图像