How to Load Any Image From URL Without Using Any Dependency in Android? Last Updated : 05 Aug, 2021 Comments Improve Suggest changes Like Article Like Report Many applications display images from the internet using third-party APIs like Glide and Picasso to load images. This means that such applications partly depend on these services to keep themselves working fine. To make the application better, one should write their own code rather than depending on such services. In this article, we will show you how you can easily load images in your application without using any external service. Step by Step Implementation Step 1: Create a New Project in Android Studio To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project. Step 2: Add Internet permission in the AndroidManifest.xml Since images are in the form of URLs, the application will need internet permissions to parse the information. XML <uses-permission android:name="android.permission.INTERNET"/> Step 3: Create an ImageView in the layout Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. XML <?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:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <!-- The image will load in this ImageView --> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true"/> </RelativeLayout> Step 4: Program to load image from URL and display in the ImageView Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail. Kotlin import android.graphics.Bitmap import android.graphics.BitmapFactory import android.os.Bundle import android.os.Handler import android.os.Looper import android.widget.ImageView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import java.util.concurrent.Executors class MainActivity : AppCompatActivity(){ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Declaring and initializing the ImageView val imageView = findViewById<ImageView>(R.id.imageView) // Declaring executor to parse the URL val executor = Executors.newSingleThreadExecutor() // Once the executor parses the URL // and receives the image, handler will load it // in the ImageView val handler = Handler(Looper.getMainLooper()) // Initializing the image var image: Bitmap? = null // Only for Background process (can take time depending on the Internet speed) executor.execute { // Image URL val imageURL = "https://media.geeksforgeeks.org/wp-content/cdn-uploads/gfg_200x200-min.png" // Tries to get the image and post it in the ImageView // with the help of Handler try { val `in` = java.net.URL(imageURL).openStream() image = BitmapFactory.decodeStream(`in`) // Only for making changes in UI handler.post { imageView.setImageBitmap(image) } } // If the URL doesnot point to // image or any other kind of failure catch (e: Exception) { e.printStackTrace() } } } } Output: We can see that the image loads successfully. This means that the application works perfectly as intended. Comment More infoAdvertise with us Next Article How to Load Any Image From URL Without Using Any Dependency in Android? aashaypawar Follow Improve Article Tags : Kotlin Android Similar Reads How to Load Image From URL in Android using Jetpack Compose? Most of the applications in android use images for displaying some useful information within the applications. Images are considered as easy to convey information to the user. An android application uses more than 100 different types of images. So it is not practically possible to add all the images 4 min read How to Share Image From URL with Intent in Android? In this article, we will see how can we share images and text with Android Intent. In this activity URL of an image to be shared will be given with extra text and we will open the Dialog where the user chooses using which he wants to share this image as shown on the screen. A sample video is given b 5 min read How to Load SVG from URL in Android ImageView? It is seen that many Android apps require to use of high-quality images that will not get blur while zooming. So we have to use high-quality images. But if we are using PNG images then they will get blur after zooming because PNG images are made up of pixels and they will reduce their quality after 4 min read How to Open PDF From URL in Android Without Any Third Party Libraries? There are lots of libraries that are available online but it takes lots of space and time to render you can see these articles if you want to load pdf using third-party libraries Load PDF from URL in Android. But today we are going to load PDFs without using any third-party libraries the main purpos 4 min read How to Share Image of Your App with Another App in Android? Most of the time while using an app we want to share images from the app to another app. While using Many Social Media Platforms we find this feature to be very useful when we want to share information from one app to another. The Android Intent resolver is used when sending data to another app as p 4 min read How to Play Audio From URL in Android using Jetpack Compose? Many apps require the feature to add the audio feature in their application and there are so many audio files that we have to play inside our application. If we will store so many audio files inside our application, then it will increase the size of the app and this may reduce the user base due to t 7 min read Fresco Image Loading Library in Android with Example Fresco is one of the famous image loading libraries from URLs in Android. It is a powerful library for displaying and managing images from URLs. This library can load images from Users' devices, servers, and other local sources. The most important feature of this library is to show a placeholder ima 3 min read How to Download File from URL in Android Programmatically using Download Manager? In this article, we are going to learn how to download files from an URL using Download Manager. Here we will be simply adding the link of the file available online. When we click on the Button it will be downloaded automatically to our phone storage. This is a very frequently used feature as we can 2 min read How to Play Video from URL in Android? In this article, you will see how to play a video from a URL on Android. For showing the video in our Android application we will use the VideoView widget. The VideoView widget is capable of playing media files, and the formats supported by the VideoView are 3gp and MP4. By using VideoView you can p 3 min read Android - Extract Data From JSON Array using Retrofit Library with Kotlin In the android application, the response from the server is in the form of JSON. We can get to see either a JSON Array or a JSON Object in the response. JSON Array is the list of data which is having similar JSON objects. In the previous article, we have taken a look at How to parse data from JSON O 7 min read Like