毕加索图像加载问题与Android 9.0 Pie

2022-09-03 03:11:43

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

Picasso.get().setLoggingEnabled(true);

他有消息日志:

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

答案 1

尝试在清单文件的应用程序标记中使用!因为我在使用Android Volley时遇到了同样的问题!android:usesCleartextTraffic="true"

根据安卓文档

指示应用是否打算使用明文网络流量,如明文 HTTP。面向 API 级别 27 或更低的应用程序的默认值为 。以 API 级别 28 或更高版本为目标的应用默认为 。"true""false"

当该属性设置为 时,平台组件(例如,HTTP 和 FTP 堆栈、DownloadManager、MediaPlayer)将拒绝应用使用明文流量的请求。强烈建议第三方库也遵守此设置。避免明文流量的关键原因是缺乏机密性,真实性和防篡改保护:网络攻击者可以窃听传输的数据,并在不被检测到的情况下对其进行修改。链接"false"


答案 2

我知道作品的答案,但这将允许所有连接都是http而不是所有东西,我想这不是你在2018年想要的。android:usesCleartextTraffic="true"

如果您知道要进入的域并且信任它,则最好使用网络安全配置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>

查看唯一 for 及其子项。cleartextTrafficPermitted="true"secure.example.com

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

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


推荐