显示来自此特定网址的图像

时间:2019-07-08 14:31:33

标签: android android-glide

我无法从此特定的URL检索图像以在Android上使用Glide显示它。 (http://tnm5.ma/wp-content/uploads/2019/03/11juin.jpg

我尝试过的其他任何一种链接,但格式不同,都无法使用。我还尝试了Picasso框架。没事

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.scrim_layout);


    ImageView imageView = (ImageView) findViewById(R.id.img);

    Glide.with(this).load("http://tnm5.ma/wp-content/uploads/2019/03/11juin.jpg").into(imageView);

}

我没有收到任何错误消息。只是不显示

1 个答案:

答案 0 :(得分:1)

我发现了为什么映像无法加载的问题,它引发了如下所示的运行时异常

  

java.io.IOException:不允许到tnm5.ma的明文HTTP通信

根据docs

  

从Android 9(API级别28)开始,默认情况下禁用明文支持。

因此,您必须将属性android:usesCleartextTraffic设置为true

android:usesCleartextTraffic

  

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

要解决此问题,请在清单中的android:usesCleartextTraffic="true"内使用application tag

<application
     ...
     android:usesCleartextTraffic="true"
     ...>
     ...
</application>
相关问题