Skip to main content

Load Image from URL in Android

How to show/load Image from URL in Android App



Today, we are going to learn how we can load or show an image from the internet or URL or link and show it in the ImageView in your android app.

Let's start by creating a new android project.

After creating the project we have to add our dependency to the app level Gradle file.

Open your build.gradle (Module: app) and add these dependencies



After adding the dependencies, hit the sync now button at the top right corner.

This will add the glide dependency in your project. Now open your activity xml file and add an ImageView. Like this.



We have a ConstraintLayout as parent layout and in the ConstraintLayout, we have a child ImageView and we set its id imageView.

Now open your activity java file, and add this code in your onCreate method.



In the above code, first, we are getting our image view from xml by using findViewById.

And then, we are calling the glide library, and it's with function and passing context and after that, we are calling load function which accepts the URL of the image and finally we load an image into our imageView by calling into function.

At this point, if we run our application nothing will happen. Why?

Because we are using the internet to load an image and to do that we need to specify the permission in the manifest file like this.



Add this code above the application opening tag in the manifest.

See also: Make Image Slider in Android

Now run your application and wait for the application to load the image and then congrats you successfully load an Image from the internet or link or url in your android application.



If you learn something new then share this article on how to load an image from url or link, with your friends and mates.

Popular Posts

How to make splash screen in Android in 2020 [Best Guide]

Custom Switch in Android | Akshayrana.in | Android Tutorial

Working with Bottom Navigation bar in Android [Full Guide]