Android9.0使用Glide加载图片问题

735 阅读1分钟

今天公司项目出了一个问题,部分手机加载图片可以显示,部分手机加载图片不能显示,经查发现不能显示图片的手机均为9.0手机,按照网上的思路在AndroidManifest.xml的application中添加了一条属性,即:android:usesCleartextTraffic="true",测试可以显示,具体原因为:"""在Android9.0的机器上,默认不支持http的访问,所有网络访问必须使用https".

此时AndroidManifest.xml中的application如下:

<application 
android:allowBackup="true" 
android:icon="@mipmap/ic_icon" 
android:label="@string/app_name" 
android:roundIcon="@mipmap/ic_icon" 
android:supportsRtl="true" 
android:usesCleartextTraffic="true" 
android:theme="@style/diCheGouTheme">

但是我发现9.0系统的手机中部分图片还是可以显示的,而且并未设置android:usesCleartextTraffic="true"属性,仔细对比发现这些显示显示的图片使用的上下文均为全局上下文,即:DcgApp.getAppContext(),具体原因不明.

所以这个问题有两种解决方法.