Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
How to Use Game Mode API in Android 13?
Next article icon

How to Add Memes Using API Call in Android?

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Application Programming Interface calling is the process of making requests to external web-based services to retrieve or manipulate data. APIs provide a standardized way for different software applications to communicate with each other. It involves sending a request from one application to another over the internet using a specific set of rules and protocols. The requesting application sends an API request to the target application, which then processes the request and sends back a response containing the requested data. API calls can be done using various programming languages and tools, such as cURL, Postman, Python, Java, and many others. 

Meme

A meme is a cultural phenomenon that spreads rapidly through the internet, typically in the form of humorous images, video, or piece of text that is shared widely and often parodied or adapted.

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. Note that select Java as the programming language.

Step 2: Working with the activity_main.xml file

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"?> <LinearLayout      xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     android:gravity="center_horizontal"     android:background="#F3FCFF"     tools:context=".MainActivity">      <TextView         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="My Meme App"         android:textSize="40sp"         android:textStyle="bold"         android:textColor="#006875"         android:layout_marginTop="40dp"/>      <androidx.cardview.widget.CardView         android:layout_width="340dp"         android:layout_height="500dp"         android:layout_marginTop="15dp"         android:layout_gravity="center_horizontal"         app:cardCornerRadius="25dp">          <RelativeLayout             android:layout_width="wrap_content"             android:layout_height="wrap_content">              <ImageView                 android:id="@+id/imgMeme"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:paddingLeft="20dp"                 android:scaleType="fitCenter"                 android:paddingTop="20dp"                 android:paddingRight="20dp" />              <ProgressBar                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_centerVertical="true"                 android:layout_marginLeft="150dp"                 android:visibility="invisible"/>         </RelativeLayout>       </androidx.cardview.widget.CardView>      <androidx.cardview.widget.CardView         android:layout_width="200dp"         android:layout_height="60dp"         app:cardCornerRadius="30dp"         android:layout_marginTop="20dp"         android:outlineAmbientShadowColor="@color/black"         android:outlineSpotShadowColor="@color/white">          <RelativeLayout             android:layout_width="wrap_content"             android:layout_height="wrap_content">             <ImageView                 android:id="@+id/btnShare"                 android:layout_width="40dp"                 android:layout_height="40dp"                 android:layout_marginTop="10dp"                 android:layout_marginLeft="30dp"                 android:src="@drawable/share"/>              <ImageView                 android:id="@+id/btnNext"                 android:layout_width="40dp"                 android:layout_height="40dp"                 android:layout_marginTop="10dp"                 android:src="@drawable/next"                 android:layout_marginLeft="120dp"/>         </RelativeLayout>     </androidx.cardview.widget.CardView>  </LinearLayout> 

Output UI:

 

Step 3:

In your java folder create a new java file. Add this code to your new Java file.

Java
package com.anas.memeshareapp;  import android.content.Context; import android.graphics.Bitmap; import android.util.LruCache;  import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.toolbox.ImageLoader; import com.android.volley.toolbox.Volley;  public class MySingleton {      private static MySingleton instance;     private RequestQueue requestQueue;     private ImageLoader imageLoader;     private static Context ctx;      private MySingleton(Context context) {         ctx = context;         requestQueue = getRequestQueue();          imageLoader = new ImageLoader(requestQueue,                 new ImageLoader.ImageCache() {                     private final LruCache<String, Bitmap>                             cache = new LruCache<String, Bitmap>(20);                      @Override                     public Bitmap getBitmap(String url) {                         return cache.get(url);                     }                      @Override                     public void putBitmap(String url, Bitmap bitmap) {                         cache.put(url, bitmap);                     }                 });     }      public static synchronized MySingleton getInstance(Context context) {         if (instance == null) {             instance = new MySingleton(context);         }         return instance;     }      public RequestQueue getRequestQueue() {         if (requestQueue == null) {             // getApplicationContext() is key, it keeps you from leaking the             // Activity or BroadcastReceiver if someone passes one in.             requestQueue = Volley.newRequestQueue(ctx.getApplicationContext());         }         return requestQueue;     }      public <T> void addToRequestQueue(Request<T> req) {         getRequestQueue().add(req);     }      public ImageLoader getImageLoader() {         return imageLoader;     } } 

Step 4: Working with the MainActivity.java file

Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file.

Java
package com.anas.memeshareapp;  import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity;  import android.content.Intent; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.view.View; import android.widget.Button; import android.widget.ImageView;  import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.JsonObjectRequest; import com.bumptech.glide.Glide; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.target.Target;  import org.json.JSONException; import org.json.JSONObject;  public class MainActivity extends AppCompatActivity {      ImageView imgMeme;     ImageView btnNext;     ImageView btnShare;      String url ;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          imgMeme = findViewById(R.id.imgMeme);         btnNext = findViewById(R.id.btnNext);         btnShare = findViewById(R.id.btnShare);           apiCall();         btnNext.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                  apiCall();             }         });          btnShare.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                  BitmapDrawable bitmapDrawable = (BitmapDrawable) imgMeme.getDrawable();                 Bitmap bitmap = bitmapDrawable.getBitmap();                  String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(),bitmap,"Title",null);                 Uri uri = Uri.parse(bitmapPath);                 Intent intent = new Intent(Intent.ACTION_SEND);                 intent.setType("image/*");                 intent.putExtra(Intent.EXTRA_STREAM,uri);                 startActivity(Intent.createChooser(intent,"share to :"));             }         });     }      public void apiCall(){         url = "https://meme-api.com/gimme";          JsonObjectRequest jsonObjectRequest = new JsonObjectRequest                 (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {                      @Override                     public void onResponse(JSONObject response) {                         try {                              url = response.getString("url");                             Glide.with(MainActivity.this).load(url).into(imgMeme);                          }                         catch (JSONException e){                             e.printStackTrace();                         }                      }                 }, new Response.ErrorListener() {                      @Override                     public void onErrorResponse(VolleyError error) {                       }                 });          MySingleton.getInstance(this).addToRequestQueue(jsonObjectRequest);     } } 

Step 6: Make some changes in your gradle file

Add these dependencies to it 

implementation 'com.android.volley:volley:1.2.1'  implementation 'com.github.bumptech.glide:glide:4.15.1'
 

Note: Make sure that your emulator is connected to the internet.

Output:

 

Next Article
How to Use Game Mode API in Android 13?
author
shrutisaini1415
Improve
Article Tags :
  • Android

Similar Reads

  • How to Make a Joke App in Android Using API Call?
    Jokes are the best way to keep the face smiling. With the power of technology, we can create apps that provide instant access to a broad Category(i.e. animal, money, career, dev etc ) of jokes at any time. In this article, we will create a Joke App in Android that uses API calls to fetch jokes from
    7 min read
  • How to Make an Motivational Quotes App in Android using API Call?
    In this article, we will see the process of building a Motivational Quotes App for Android that fetches random quotes from an API and displays them to the user. By the end of this article, we will have a Complete Android application that connects to an API, retrieves motivational quotes and author n
    5 min read
  • How to Use Game Mode API in Android 13?
    It has been a really long time since Android has a dedicated game mode of its own, but it appears that Google has finally listened to all the gamers out there. When the user chooses the appropriate game mode, the Game Mode API enables you to optimize your game for the greatest performance or the lon
    4 min read
  • How to Create a News App in Android?
    Networking is an integral part of android development, especially when building data-driven clients. The java class mainly used for network connections is HttpUrlConnection. The class requires manual management of data parsing and asynchronous execution of requests. For network operations, we are be
    10 min read
  • How to Post Data to API using Volley in Android?
    We have seen reading the data from API using Volley request with the help of GET request in Android. With the help of GET Request, we can display data from API in JSON format and use that data inside our application. In this article, we will take a look at posting our data to API using the POST requ
    5 min read
  • How to Add Blogs in Social Media Android App?
    This is the Part 5 of "Build a Social Media App on Android Studio" tutorial, and we are going to cover the following functionalities in this article: We are going to add blogs by any user. Here we are going to work in AddBlogs Fragment where the user will be adding a blog with a title, description,
    7 min read
  • How to Build a ChatGPT Like App in Android using OpenAI API?
    Chat GPT is nowadays one of the famous AI tools which are like a chatbot. This chatbot answers all the queries which are sent to it. In this article, we will be building a simple ChatGPT-like android application by integrating the OpenAI API(ChatGPT) where we can ask any question and get an appropri
    5 min read
  • How to Generate API Key for Using Google Maps in Android?
    For using any Google services in Android, we have to generate an API key or we have to generate some unique key for using that service provided by Google. So Maps is one of the famous and most used services provided by Google. Maps can be seen in each and every app provided by Google and we also can
    3 min read
  • How to Post Data to API using Retrofit in Android?
    We have seen reading data from API in our Android app in Android Studio. For reading data from API, we use GET request to read our data which is in JSON format. In this article, we will take a look at adding data to REST API in our Android App in Android Studio. What we are going to build in this ar
    6 min read
  • How to Use Canvas API in Android Apps?
    Canvas API is also one of the most used in Android. The name of the API itself tells us that the API is being used for drawing on the drawing board. With the help of this API, we can draw different types of shapes and create custom UI components that are not present in Android. In this article, we w
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences