johnrao07
johnrao07

Reputation: 6908

How to display JPEG images for url starts with `http://` using Glide

The following code works to display PNG images but it doesn't work for the JPG images

GlideApp.with(playerBinding.ivLogoHomeTeam.context)
        .load("https://[email protected]")
        .into(playerBinding.ivLogoHomeTeam)

XML:

<de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/iv_logo_home_team"
                android:layout_width="@dimen/match_item_team_logo"
                android:layout_height="@dimen/match_item_team_logo"
                android:layout_marginStart="@dimen/unit_dp_10"
                android:layout_marginLeft="@dimen/unit_dp_10"
                android:layout_marginEnd="@dimen/unit_dp_10"
                android:layout_marginRight="@dimen/unit_dp_10"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:srcCompat="@drawable/ic_launcher_background" />

EDIT: JPEG images are working for HTTPS images, while the HTTP images are not working. How do we dislpay the HTTP images?

Upvotes: 0

Views: 1877

Answers (1)

Lenoarod
Lenoarod

Reputation: 3610

it is the Http permission problem. you should add the following for http request.

<application
android:usesCleartextTraffic="true"

/>

for detail, you can see my this answer.

but I also give how to find the error in Glide. firstly, you can use the Gilde debug option to find the info to solve the problem.

If you have access to the device, run this command adb shell setprop log.tag.Glide DEBUG, it will log both successful and failed requests and differing levels of detail depending on the log level. you can call setLogLevel(int) to set the level.

you can also use the listener to find the exception error.

Glide.with(fragment)
   .load(url)
   .listener(new RequestListener() {
       @Override
       boolean onLoadFailed(@Nullable GlideException e, Object model,    
         Log.e(TAG, "Load failed", e);
         return false; // Allow calling onLoadFailed on the Target.
       }

       @Override
       boolean onResourceReady(R resource, Object model, Target<R> target,
           DataSource dataSource, boolean isFirstResource) {
         // Log successes here or use DataSource to keep track of cache hits and misses.
         return false;
       }
    })
    .into(imageView);

Upvotes: 2

Related Questions