【问题标题】:OkHttp - detect image download timeoutOkHttp - 检测图像下载超时
【发布时间】:2017-07-05 21:30:49
【问题描述】:

在我的 android 应用程序中,我使用 glide 进行图像加载,使用 OkHttp 进行网络操作。

如果图像下载时间超过超时时间(例如 10 秒),我想使用 glide 显示错误图像。我使用 GlideModule 将 OkHttpClient 与 glide 连接起来,但 OkHttpClient 的 readTimeout 方法似乎没有像我想象的那样工作 - 它没有等待图像下载完成,而只是等待读取字节。

所以我的问题是:如果图像下载操作超过设置的超时时间,我如何中止 okhttp 请求?我尝试在 Interceptor 中执行此操作,但当时没有成功。

【问题讨论】:

    标签: java android okhttp android-glide okhttp3


    【解决方案1】:

    这在 OkHttp 中没有实现。我们正在跟踪whole operation timeouts here

    如果您不耐烦,您可以使用ScheduledExecutorService 或类似名称在指定时间后取消通话。

    【讨论】:

      猜你喜欢
      • 2011-05-04
      • 1970-01-01
      • 2014-03-25
      • 1970-01-01
      • 2019-07-07
      • 1970-01-01
      • 2019-06-30
      • 2016-06-30
      • 1970-01-01
      相关资源
      最近更新 更多