You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Glide加载特定格式URL图片失败求助

解决Glide无法加载指定HTTP图片URL的问题

核心原因及对应解决方法

1. Android 9+ 默认限制明文HTTP流量

从Android 9(API 28)开始,系统默认拦截明文(HTTP)网络请求,仅允许HTTPS协议。你的目标图片URL使用HTTP协议,这是加载失败的最可能原因。

解决步骤:

  • 在res/xml目录下创建network_security_config.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <!-- 允许目标域名的明文HTTP请求 -->
        <domain includeSubdomains="true">file.koreafilm.or.kr</domain>
    </domain-config>
</network-security-config>
  • 在AndroidManifest.xml的<application>标签中引入该配置:
<application
    ...
    android:networkSecurityConfig="@xml/network_security_config">
    ...
</application>

2. 确认Glide依赖与配置

确保使用的Glide为最新稳定版,避免版本兼容问题。在模块级build.gradle中检查依赖:

implementation 'com.github.bumptech.glide:glide:4.16.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.16.0'

3. 添加调试监听定位具体错误

给Glide加载流程添加监听,打印失败详情,便于排查其他潜在问题:

Glide.with(context)
        .load(movieImageArray.get(position))
        .error(R.drawable.gray_profile)
        .fallback(R.drawable.profile)
        .listener(new RequestListener<Drawable>() {
            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                if (e != null) {
                    e.printStackTrace();
                }
                return false;
            }

            @Override
            public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                return false;
            }
        })
        .into(holder.imageMovieResult);

额外检查项

  • 先在设备浏览器中打开目标URL,确认网络可正常访问该图片;
  • 若URL存在特殊重定向逻辑,可考虑集成Glide的OkHttp扩展来处理复杂网络请求。

内容的提问来源于stack exchange,提问作者kane

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 08:20:26