java - Android glide 无法在 Android 4.X 中加载图片
问题描述
我正在使用 Glide v4.11 从网络加载图片,在 android 5.0 或更高版本中一切正常,但在 android 4.X 中无法加载图片。
这是我的代码:
RequestOptions options = new RequestOptions()
.placeholder(android.R.drawable.progress_horizontal)
.error(android.R.drawable.presence_offline)
.diskCacheStrategy(DiskCacheStrategy.ALL);
Glide.with(context)
.load(data.getImage_url())
.apply(options)
.into(holder.thumbnail);
这是 Android 4.4 上的 LogCat:
W/Glide: Load failed for https://www.gradientapi.xyz/generate/w/1000/h/500 with size [188x263]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
javax.net.ssl.SSLHandshakeException(javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb85422a0: Failure in SSL library, usually a protocol error
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:766 0xa744e990:0x00000000))
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
There was 1 cause:
javax.net.ssl.SSLHandshakeException(javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb85422a0: Failure in SSL library, usually a protocol error
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:766 0xa744e990:0x00000000))
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
There was 1 cause:
javax.net.ssl.SSLHandshakeException(javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb85422a0: Failure in SSL library, usually a protocol error
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:766 0xa744e990:0x00000000))
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb85422a0: Failure in SSL library, usually a protocol error
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:766 0xa744e990:0x00000000)
我在网上搜索,发现 Android 4.4 只支持 TLS 1.0。
这可能是问题?如果是,有什么解决方案吗?
解决方案
这是握手异常。在早于Android 5.0
TLSv1.1
和的设备TLSv1.2
上,默认情况下不启用协议,这就是发生此异常的原因。
您可以在应用程序的类 onCreate 方法中尝试此操作:
if (Build.VERSION.SDK_INT == 19) {
try {
ProviderInstaller.installIfNeeded(this);
} catch (Exception ignored) {
}
}
此外,您可以查看此 github 问题以获得更好的解决方案。
推荐阅读
- tensorflow - 如何在 sagemaker 训练实例中指定 cuda 版本
- oracle - 从时间中提取小时并添加转换为小时的分钟并从时间中提取分钟并找到提醒(模数)
- regex - 尝试使用 sed 从 bash 脚本编辑配置文件以编辑键/值对
- r - 大家好,我想根据时间(x)从最小到最大排列我的事件(y)。但我希望这是一个循环
- jquery - 基于搜索字符串的jQuery隐藏列
- sql - 从 Excel 导入 Postgresql 中的“错误:未终止的 csv 引用字段” - 仅限大文件
- javascript - 不会阻止输入无效数字,但“element.value”不允许我更正它们
- javascript - 无效的挂钩调用。钩子只能在里面调用......如何解决这个维护反应类组件
- oracle - 登录 apex 应用程序后,用户将根据其角色重定向到页面
- android - 列表项在android中保存上下文的引用是否有好处