0

Here is my code where I used Picasso as well as glide library, but the image did not get displayed in the ImageView. I even tried HTTP method, didn't work

String icon = pojo.getCurrent().getWeather().get(0).getIcon();
String iconUrl = "http://openweathermap.org/img/w/" + icon + ".png";
Log.v("AAA",iconUrl);
//Picasso.get().load(iconUrl).resize(20,20).centerCrop().into(weatherImage); 
Glide.with(requireActivity().getApplicationContext()).load(iconUrl).into(weatherImage);

I also added the dependencies

this is the layout file

  <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="@drawable/shape"
       android:orientation="horizontal">

       <Button
           android:id="@+id/id_weather_refresh"
           android:layout_width="30dp"
           android:layout_height="40dp"
           android:drawableEnd="@drawable/ic_baseline_refresh"
           android:padding="5dp"
           android:textColor="#FFFFFF" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:orientation="vertical">
                    <TextView
                        android:id="@+id/id_temperature"
                        android:layout_width="fill_parent"
                        android:layout_height="60dp"
                        android:fontFamily="casual"
                        android:gravity="center"
                        android:text="-:-/-:-"
                        android:textColor="#040404"
                        android:textSize="34sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/id_envType"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center|center_vertical"
                        android:text="---------"
                        android:textColor="#716F6F" />


                </LinearLayout>

                <androidx.cardview.widget.CardView
                    android:layout_width="110dp"
                    android:layout_height="110dp"
                    app:cardCornerRadius="20dp">

                    <ImageView
                        android:id="@+id/id_weatherImage"
                        android:layout_width="110dp"
                        android:layout_height="110dp"
                        android:src="@drawable/ic_launcher_background" />
                </androidx.cardview.widget.CardView>

            </LinearLayout>

I have posted an image of what's happening, actually it has to download the image from internet and display it there, but instead it's not displaying anything.

This is the URL of the image

The error message

2022-05-11 17:06:31.754 12117-12117/com.example.clothme I/Glide: Root cause (1 of 1)
    java.io.IOException: Cleartext HTTP traffic to openweathermap.org not permitted
        at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:127)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:462)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131)
        at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:100)
        at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:56)
        at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)
        at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:164)
        at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:154)
        at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:62)
        at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)
        at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:70)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)
2022-05-11 17:06:32.362 12117-16853/com.example.clothme I/example.clothm: Waiting for a blocking GC Instrumentation
2022-05-11 17:06:35.370 12117-16853/com.example.clothme I/example.clothm: Waiting for a blocking GC Instrumentation
2022-05-11 17:06:35.379 12117-16853/com.example.clothme I/example.clothm: WaitForGcToComplete blocked Instrumentation on ProfileSaver for 9.615ms

Atharv
  • 43
  • 5
  • 1
    Check the verbose logs see if glide is throwing any error . – ADM May 11 '22 at 11:35
  • its throwing error, ill post the error message – Atharv May 11 '22 at 11:37
  • how to resolve that error? – Atharv May 11 '22 at 11:39
  • 1
    https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted – ADM May 11 '22 at 11:40
  • 1
    I think this topic will solve your problem: https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted – jpsf May 11 '22 at 11:44
  • Thank you, it worked. I refered to the links and tried the first option i.e changing http to https and it worked. Thank you once again! @ADM and jpsf – Atharv May 11 '22 at 11:49
  • 1
    @Atharv changing http to https is not always works, here's an example [URL](http://hd.wallpaperswide.com/thumbs/peaceful-t2.jpg) with **HTTP** and the same [URL](https://hd.wallpaperswide.com/thumbs/peaceful-t2.jpg) but with **HTTPS**, as you can see here, the **HTTPS** url is not working. – Mouaad Abdelghafour AITALI May 11 '22 at 18:26

1 Answers1

0

Add android:usesCleartextTraffic="true" to your Application Tag in your AndroidManifest.xml

Starting with Android 9.0 (API level 28), cleartext support is disabled by default. So all requests from http protocol will no longer accepted