Android 9.0 Pie的Picasso图像加载问题

tej*_*raj 13 java android picasso

我无法使用Android 9.0 Pie中的Picasso库加载图像.实际上,它适用于以下版本.它没有显示任何错误消息.有人用Github分享了他的日志

Picasso.get().setLoggingEnabled(true);
Run Code Online (Sandbox Code Playgroud)

他有消息日志:

2018-10-19 13:13:20.467 24840-24862/com.xyz.test.testpicasso D/ViewContentFactory: initViewContentFetcherClass
2018-10-19 13:13:20.467 24840-24862/com.xyz.test.testpicasso I/ContentCatcher: ViewContentFetcher : ViewContentFetcher
2018-10-19 13:13:20.467 24840-24862/com.xyz.test.testpicasso D/ViewContentFactory: createInterceptor took 0ms
2018-10-19 13:13:20.468 24840-24862/com.xyz.test.testpicasso I/ContentCatcher: Interceptor : Catcher list invalid for com.xyz.test.testpicasso@com.xyz.test.testpicasso.MainActivity@147874166
2018-10-19 13:13:20.468 24840-24862/com.xyz.test.testpicasso I/ContentCatcher: Interceptor : Get featureInfo from config pick_mode
2018-10-19 13:13:20.485 24840-24840/com.xyz.test.testpicasso D/Picasso: Main        created      [R1] Request{https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png}
2018-10-19 13:13:20.492 24840-24864/com.xyz.test.testpicasso D/Picasso: Dispatcher  enqueued     [R1]+6ms 
2018-10-19 13:13:20.492 24840-24866/com.xyz.test.testpicasso D/Picasso: Hunter      executing    [R1]+7ms 
2018-10-19 13:13:20.555 1531-1684/? I/ActivityManager: Displayed com.xyz.test.testpicasso/.MainActivity: +114ms
2018-10-19 13:13:20.555 5475-5603/? D/PowerKeeper.Event: notifyActivityLaunchTime: com.xyz.test.testpicasso/.MainActivity totalTime: 114
2018-10-19 13:13:20.709 735-816/? W/SurfaceFlinger: Attempting to set client state on removed layer: Splash Screen com.xyz.test.testpicasso#0
2018-10-19 13:13:20.710 735-816/? W/SurfaceFlinger: Attempting to destroy on removed layer: Splash Screen com.xyz.test.testpicasso#0
2018-10-19 13:13:20.775 1531-1684/? I/Timeline: Timeline: Activity_windows_visible id: ActivityRecord{821c51 u0 com.xyz.test.testpicasso/.MainActivity t4372} time:9356677
2018-10-19 13:13:21.003 24840-24864/com.xyz.test.testpicasso D/Picasso: Dispatcher  retrying     [R1]+518ms 
2018-10-19 13:13:21.004 24840-24872/com.xyz.test.testpicasso D/Picasso: Hunter      executing    [R1]+519ms 
2018-10-19 13:13:21.513 24840-24864/com.xyz.test.testpicasso D/Picasso: Dispatcher  retrying     [R1]+1027ms 
2018-10-19 13:13:21.514 24840-24877/com.xyz.test.testpicasso D/Picasso: Hunter      executing    [R1]+1028ms 
2018-10-19 13:13:21.516 24840-24864/com.xyz.test.testpicasso D/Picasso: Dispatcher  batched      [R1]+1030ms for error
2018-10-19 13:13:21.717 24840-24864/com.xyz.test.testpicasso D/Picasso: Dispatcher  delivered    [R1]+1232ms
Run Code Online (Sandbox Code Playgroud)

Int*_*der 40

尝试android:usesCleartextTraffic="true"在Manifest文件的应用程序标记中使用!因为我使用Android Volley面临同样的问题!

根据Android文档

指示应用程序是否打算使用明文网络流量,例如明文HTTP.默认值是true".当属性设置为"false"时,平台组件(例如,HTTP和FTP堆栈,DownloadManager,MediaPlayer)将拒绝应用程序使用明文流量的请求.强烈建议第三方图书馆遵守此设置.避免明文流量的关键原因是缺乏机密性,真实性和防止篡改:网络攻击者可以窃听传输的数据并在不被检测的情况下对其进行修改. 链接

  • 在现代应用中允许HTTP流量确实不是一个好主意。这可能导致许多安全问题(调试原因除外)。至少您需要像@QuentinKlein答案中那样限制域。要获得全面支持,您可以在[此处](https://www.raywenderlich.com/5634-securing-network-data-tutorial-for-android)进行检查。 (2认同)

Que*_*ein 15

我知道答案是android:usesCleartextTraffic="true"有效的,但是这将允许所有连接都是http 而不是一切,我想这不是你想要的2018年.

如果您知道您正在进入的域http并且您信任它,那么最好使用网络安全配置.

在中定义一个xml文件 res/xml/network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">secure.example.com</domain>
    </domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)

cleartextTrafficPermitted="true"只看到secure.example.com它和它的潜艇.

然后在你的AndroidManifest.xml,添加android:networkSecurityConfig="@xml/network_security_config"

您可以添加多个域,具有多个配置,确保其中一些域为https或相反.看起来更安全恕我直言.