Solution for Glide failed to load image in android pie 9.0

Image loading issues in glide android pieid Pie 9.0

Solution for Glide failed to load image in android pie 9.0

Hello, I have seen that in the Android latest version 28.0 or I can say in Android Pie 9.0 when we are using Glide for image loading then nothing is loaded. Actually this thing accrued by Network security configuration. So, I have found some solution for that.

 

First Option:

Add a Network Security Configuration file in your project. The Network Security Configuration feature uses an XML file where you specify the settings for your app. You must include an entry in the manifest of your app to point to this file. The following code excerpt from a manifest demonstrates how to create this entry:

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config"
                    ... >
        ...
    </application>
</manifest>

 

Your network_security_config.xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config>
        <domain includeSubdomains="true">example.com</domain>
        <trust-anchors>
            <certificates src="@raw/my_ca"/>
        </trust-anchors>
    </domain-config>
</network-security-config>

 

Second Option:

The second option is simple, simply add one line in your AndroidManifest.xml

android:usesCleartextTraffic="true"

 

This line should be placed in your AndroidManifest.xml within the application tag, Let's see the example:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.legendblogs.glideTest">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:usesCleartextTraffic="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 

About Glide

Glide is a fast and efficient image loading library for Android focused on smooth scrolling. Glide offers an easy to use API, a performant and extensible resource decoding pipeline and automatic resource pooling. Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs. Glide includes a flexible API that allows developers to plug into almost any network stack. By default, Glide uses a custom HttpUrlConnection based stack, but also includes utility libraries plug into Google’s Volley project or Square’s OkHttp library instead.

Glide uses a simple fluent API that allows users to make most requests in a single line:

Glide.with(fragment)
    .load(url)
    .into(imageView);

 

You may like:

Top