VOOZH about

URL: https://www.geeksforgeeks.org/android/how-to-share-a-captured-image-to-another-app-in-android/

⇱ How to Share a Captured Image to Another Application in Android? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Share a Captured Image to Another Application in Android?

Last Updated : 12 Jul, 2025

Pre-requisite: How to open a Camera through Intent and capture an image

In this article, we will try to send the captured image (from this article) to other apps using Android Studio.

Approach: The image captured gets stored on the external storage. Hence we need to request permission to access the files from the user. So take permission to access external storage permission in the manifest file.

Here pictureDir(File) is pointing to the directory of external storage named DIRECTORY_PICTURES

File pictureDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"CameraDemo");

In the onCreate() method, check whether the directory pictureDir is present or not. If not then create the directory with the code below

if(!pictureDir.exists()) {
 pictureDir.mkdirs();
}

Create another method called callCameraApp() to get the clicked image from external storage.

  • Capture the image using Intent
  • Create a file to store the image in the pictureDir directory.
  • Get the URI object of this image file
  • Put the image on the Intent storage to be accessed from other modules of the app.
  • Pass the image through intent to startActivityForResult()

Share this image to other apps using intent.

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

For the sake of this article, we will be selecting Gmail and will be sending this image as an attachment in a mail.

startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Below is the Complete Implementation of the above Approach:

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. The code for that has been given in both Java and Kotlin Programming Language for Android.

Step 2: Adding the Required Permissions in the Manifest File 

Navigate to the app > AndroidManifest.xml file and add the below permissions to it. 

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

Step 3: Working with the XML Files

Next, go to the activity_main.xml file, which represents the UI of the project. Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in more detail.

Step 4: Working with the MainActivity File

Go to the MainActivity File and refer to the following code. Below is the code for the MainActivity File. Comments are added inside the code to understand the code in more detail.

Comment
Article Tags:
Article Tags:

Explore