Android 上的 Picasso 未加载此图片 Uri

Picasso on Android does not load this image Uri

此图片 URI:http://d3lca4hm3yw4jx.cloudfront.net/medialibrary/Empire+2/photos_thumb/Empire2.jpg 无法在 Picasso 中加载

它在浏览器上加载正常。

Picasso.with(this)
    .load(Uri.parse(
        "http://d3lca4hm3yw4jx.cloudfront.net/medialibrary/Empire+2/photos_thumb/Empire2.jpg"))
    .fit()
    .error(android.R.drawable.stat_notify_error)
    .centerCrop()
    .into(iv, new Callback() {
      @Override
      public void onSuccess() {

      }

      @Override
      public void onError() {
        Log.d("error", "error");
      }
    });

设置:

OkHttpClient client = new OkHttpClient();
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
client.interceptors().add(logging);
Picasso.setSingletonInstance(new Picasso.Builder(this).downloader(new OkHttpDownloader(client))
    .memoryCache(new LruCache(50 * 1024 * 1024))
    .indicatorsEnabled(true)
    .loggingEnabled(true)
    .build());

使用的库

compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.squareup.okhttp:okhttp:2.7.0'
compile 'com.squareup.okhttp:logging-interceptor:2.7.0'
compile 'com.squareup.picasso:picasso:2.5.2'

可以在这里看到整个源代码(只有一个activity)

https://github.com/slashrootv200/PicassoImageUri/blob/master/app/src/main/java/in/curium/picassotest/picassotest/MainActivity.java

编辑:

也添加了成功日志。但是我在错误方法中得到了回调。

03-20 00:59:11.112 27955-28089/in.curium.picassotest.picassotest D/OkHttp: --> GET http://d3lca4hm3yw4jx.cloudfront.net/medialibrary/Empire+2/photos_thumb/Empire2.jpg HTTP/1.1
03-20 00:59:11.112 27955-28089/in.curium.picassotest.picassotest D/OkHttp: Cache-Control: max-stale=2147483647, only-if-cached
03-20 00:59:11.112 27955-28089/in.curium.picassotest.picassotest D/OkHttp: --> END GET
03-20 00:59:11.112 27955-28089/in.curium.picassotest.picassotest D/OkHttp: <-- HTTP/1.1 504 Unsatisfiable Request (only-if-cached) (0ms)
03-20 00:59:11.112 27955-28089/in.curium.picassotest.picassotest D/OkHttp: <-- END HTTP (0-byte body)

您需要在 manifest file 中配置 INTERNET 权限。没有它,您的应用程序(以及 picasso)将无法访问互联网。

示例:

<manifest package="in.curium.picassotest.picassotest"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET"/>

<application
  android:name=".App"
 ...

从此处升级到 Picasso 版本 2.6.0-SNAPSHOT 可解决此问题。 https://oss.sonatype.org/content/repositories/snapshots/com/squareup/picasso/picasso/2.6.0-SNAPSHOT/