How to Load Images From URL Using Fresco in Android Java

In this article, we will learn how to Load Images from URL using Fresco in Java. At the end of this tutorial, you will see the following screen will be designed.

Load Images From URL Using Fresco - Handy Opinion

Dependencies

After creating a new project, Add the following dependencies in your build.gradle.

implementation 'com.facebook.fresco:fresco:2.3.0'

Make sure you Sync your project after adding the Fresco.

Add Internet Permission

We are using the URLs to load image from the internet, that why we need to include the permission of the INTERNET in our AndroidManifest.xml file.

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

Add the above permission when you are loading images from the internet. If you are loading images locally on the device then internet permission is not required.

Fresco Initialize

Now make sure to initialize the Fresco and initialized the Fresco before you call setContentView() in MainActivity.

Fresco.initialize(this);

URL for Image

We have the Images URLs and the path where we have to display the images.

Uri imageUri = Uri.parse("https://theme.zdassets.com/theme_assets/2414951/bf1e6edc7a1c61b0d9ae1cc4ec2df5a8a6046a17.png");
        SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.idSDimage);
        draweeView.setImageURI(imageUri);

MainActivity Code

package com.example.handyopinion;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView;

public class MainActivity extends Activity {

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

        Uri imageUri = Uri.parse("https://theme.zdassets.com/theme_assets/2414951/bf1e6edc7a1c61b0d9ae1cc4ec2df5a8a6046a17.png");
        SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.idSDimage);
        draweeView.setImageURI(imageUri);
    }
}

In this tutorial, we learn how to Load Images from URL with Fresco, and we have learned how the library works and how we can integrate it into your project.

If you have any questions or suggestions, feel free to ask in the comments section below.

Next Article

1. How to Load Images From URL Using Glide in Android Java
2. How to Load Multiple Images From URL in Android Using Picasso Java
3. How to Load Images From URL Using Fresco in Android Kotlin

Please share this post:
Posts created 35

Ask a Question

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

%d bloggers like this: