-1

so i was trying to load a GIF image using a link into my application, but i couldn't find how.

i tried using Glide and Picasso but i still couldn't resolve my problem, at first i thought i might have something in my app that's stopping the GIF from loading so i tried creating a new app just to test loading a GIF in an app and still couldn't load a single GIF.

I have looked around for a question like mine and tested some of the answers given but none of them worked!

so if anyone can show me a way to load a GIF in an app i would be quite thankful, and i can share the code for my app but as i stated earlier i am trying a new empty app and has no actual code in it.

  • No actual code? You will have added some code where you try to load the gif. In your app? Or in an ImageView? – blackapps Sep 02 '22 at 05:22

1 Answers1

2

There's too little information to know what happened. It would be better to show more detail about the code you tried and the result.

However, This is a Simple Example

AndroidManifest.xml:

add internet permission

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

build.gradle(:app):

add Glide Library.

implementation 'com.github.bumptech.glide:glide:4.12.0'

activity_main.xml:

add an ImageView

<ImageView
    android:id="@+id/imageView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

MainActivity.kt:

load GIF into imageView

 val url = "https://media.giphy.com/media/3o7527pa7qs9kCG78A/giphy.gif"
 Glide.with(this)
     .load(url)
     .into(imageView)
Kai
  • 271
  • 1
  • 2
  • 8
  • I just created a new app and literally copied exactly what you wrote here (just added some semicolons cause am using java) and it still fails to load the GIF. i tried checking the log and i found this : W/Glide: Load failed for https://media.giphy.com/media/3o7527pa7qs9kCG78A/giphy.gif with size [1080x2038] class com.bumptech.glide.load.engine.GlideException: Failed to load resource –  Sep 02 '22 at 13:33
  • Are there more logs below the `Failed to load resource`? Like this: `There was 1 root cause: com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1) call GlideException#logRootCauses(String) for more detail Cause (1 of 1): class` – Kai Sep 02 '22 at 14:48
  • ok so for some reasons now it is working, but when i tried to implement it in my real app i get this message in the logcat : com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1) –  Sep 02 '22 at 15:53
  • + I think the problem might be related to the message shown in the Logcat :Caused by: java.io.IOException: Cleartext HTTP traffic to d205bpvrqc9yn1.cloudfront.net not permitted –  Sep 02 '22 at 15:55
  • so i have fixed my problem, i had to add this in my manifest file under the application tag : android:usesCleartextTraffic="true" –  Sep 02 '22 at 16:13
  • 1
    Good work! You found out more info and solved the problem by yourself. – Kai Sep 02 '22 at 16:39
  • thanks, although your help have saved me a lot of time an researching, so thanks for the help, again. –  Sep 02 '22 at 17:46