VOOZH about

URL: https://www.geeksforgeeks.org/android/how-to-build-a-photo-viewing-application-in-android/

⇱ How to Build a Photo Viewing Application in Android? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Build a Photo Viewing Application in Android?

Last Updated : 23 Jul, 2025

Gallery app is one of the most used apps which comes pre-installed on many Android devices and there are several different apps that are present in Google Play to view the media files present in your device. In this article, we will be simply creating a Gallery app in which we can view all the photos which we have stored on our device. Along with that, we can view individual photos in our app as well. 

What we are going to build in this article? 

We will be building a simple application in which we will be simply displaying the list of photos in the grid format and on clicking on the photo we can view that photo and can zoom in the photo to view it properly.

Important: This project cannot be run from Android 13+ since the permission READ_EXTERNAL_STORAGE is deprecated.

Step by Step Implementation

Step 1: Create a New Project

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: Add the dependency for image loading

Navigate to the Gradle Scripts > build.gradle.kts (Module :app) and add the below dependency to it. We are using Glide for loading images from paths in our ImageView

dependencies {
 ...
 implementation ("com.github.bumptech.glide:glide:4.16.0")
}

Now sync your project.


Step 3: Adding permissions to read external storage

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

<uses-permission
 android:name="android.permission.READ_EXTERNAL_STORAGE"
 android:maxSdkVersion="32" />

As we are loading all the images from our storage at a time so we have to add 2 attributes to our application tag in the AndroidManifest.xml file. Navigate to the AndroidManifest.xml file and add below two lines in your application tag of Manifest file. 

<application
 ...
 android:hardwareAccelerated="false"
 android:largeHeap="true"
 ...
</application>


Step 4: Working with the layout files 

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Now, create a new layout for each item of the recycler view and add the below code to it.


Step 5: Creating a new activity for displaying a single image

 Navigate to the app > java > {package-name}, Right-click on it, New > Empty Views Activity and name your activity as ImageDetailActivity and create a new activity. We will be using this activity to display our single image from the list of different images. 


Step 6: Creating an adapter class for the RecyclerView 

Navigate to the app > java > {package-name}, Right-click on it, New Java/Kotlin class and name your class as Adapter and add the below code to it.

Adapter File:


Step 7: 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.

MainActivity File:

Note: Make sure to grant read storage permissions. 

Refer to the following github repo to get the entire code: Photo_Viewer_Android

Output:


Comment
Article Tags:

Explore