/**
* 验证可用的url
*/
fun checkLoadUrl(context: Context, url: String, listener: CustomTarget<Drawable>) {
GlideApp.with(context)
.load(url)
.into(listener)
}
调用
// 获取可用的图片
for (String url : dataPath) {
ImageLoader.INSTANCE.checkLoadUrl(this, url, new CustomTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @androidx.annotation.Nullable Transition<? super Drawable> transition) {
mAddImgAdapter.getMImgs().add(new UploadOSSImgBean("", url));
mAddImgAdapter.notifyDataSetChanged();
}
@Override
public void onLoadCleared(@androidx.annotation.Nullable Drawable placeholder) {
// 失败
}
});
}
搜了一堆通过HttpURLConnection 或者 new URI()判断的都不行,不能在主线程做耗时操作。