3
votes

I have simple layout with ImageView

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.vbusovikov.glidetest.MainActivity">

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        />

</RelativeLayout>

And simple Glide expression to load an image to this ImageView just to test Glide

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

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

        Glide.with(this)
                .load("http://you-ps.ru/uploads/posts/2013-08/1376601606_1273.png")
                .error(R.mipmap.ic_launcher)
                .into(imageView);

    }

However, error icon is shown. What kind of problem it can be? I have proxy server on my network, and appropriate gradle.properties for that case.

systemProp.http.proxyHost=proxy******.ru
systemProp.http.proxyPort=****

But even if i try to launch this little app outside of any proxies, it won't work for some reason.

My build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.vbusovikov.glidetest"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'

    compile 'com.github.bumptech.glide:glide:3.7.0'

    testCompile 'junit:junit:4.12'
}

UPD. This simple app can load pictures from internet, but it cannot load pictures from my server. Some pictures of my server are being loaded fine, but others are not. I'm lost with this already

7
try to launch this little app outside of any proxies, it won't work for some reason, try change the image too. it work or not?Linh
Glide.with(yourclass.this)IntelliJ Amiya
Have you added the Internet permission in manifest?OBX
@IntelliJAmiya I also tried to add dontAnimate() but it didn't workTrueCH

7 Answers

5
votes

Unfortunatelly, all answers were right, but not working in my conditions. Server settings were not suitable for downloading pictures from it.

==UPDATE==

After while I figured out, that pictures on my server were broken. You can check if your picture at provided url is valid by opening this url in Mozilla Firefox. Last few kilobytes in pictures may be deleted, but browsers like Google Chrome ignores that and shows image normally. However, Firefox is more sensitive, so it helps to localize the problem.

==UPDATE2==

After another while i figured out that not only broken pictures can cause the problem. Try add android:usesCleartextTraffic="true" in Manifest in application. It will solve some issues with picture loading

2
votes

Use https insted of http in your image url.

0
votes

Try to add placeholder tag too(Looks weird but this fixed me on my side)

Glide.with(YourActivity.this)
                .load("http://you-ps.ru/uploads/posts/2013-08/1376601606_1273.png")
                .error(R.mipmap.ic_launcher)
                .placeholder(R.mipmap.placeholder)
                .into(imageView);
0
votes

The picture might be is too large to be loaded, which might fire an exception: “Bitmap too large to be uploaded into a texture”. In this case image should be scaled before setting it to View (see user1352407's answer)

Copied from user1352407's answer:

ImageView iv  = (ImageView)waypointListView.findViewById(R.id.waypoint_picker_photo);
Bitmap d = new BitmapDrawable(ctx.getResources() , w.photo.getAbsolutePath()).getBitmap();
int nh = (int) ( d.getHeight() * (512.0 / d.getWidth()) );
Bitmap scaled = Bitmap.createScaledBitmap(d, 512, nh, true);
iv.setImageBitmap(scaled);
0
votes

In my case I'm using a listener, and in onResourceReady I was returning true, but you should return false.

   Glide.with(context)
        .load(url)
        .centerCrop()
        .diskCacheStrategy(DiskCacheStrategy.RESOURCE).listener(object :
            RequestListener<Drawable> {
            override fun onLoadFailed(
                e: GlideException?,
                model: Any?,
                target: Target<Drawable>?,
                isFirstResource: Boolean,
            ): Boolean {
                imageView.visibility = GONE
                errorContainer.visibility = VISIBLE
                return true
            }

            override fun onResourceReady(
                resource: Drawable?,
                model: Any?,
                target: Target<Drawable>?,
                dataSource: DataSource?,
                isFirstResource: Boolean,
            ): Boolean {
                imageView.visibility = VISIBLE
                errorContainer.visibility = GONE
                return false  // <<<<<<<<<<<<<<<<<<<<<<<< here
            }

        }).into(imageView)
0
votes

I may be too late to answer it, but if someone still faces this issue. So I was stuck with a similar kind of a problem where I couldn't load images using Glide and after alot of research I found out the issue is not from glide but from the image URL. So to solve that I tried using a custom User-Agent and it worked for me.

GlideUrl url = new GlideUrl(imgUrl, new LazyHeaders.Builder()
                    .addHeader("User-Agent", WebSettings.getDefaultUserAgent(mContext))
                    .build());

and use this Url to load the image:

Glide.with(mContext).load(url).into(imageview);
-1
votes

it is working fine at my side..check the network and don't forgot to add the internet permission in manifest.:)