Skip to content
Related Articles
Open in App
Not now

Related Articles

Photo Picker in Android 13 with Example Project

Improve Article
Save Article
  • Last Updated : 31 Jan, 2023
Improve Article
Save Article

In many android applications, we get to see that they are picking images from the user’s device and displaying that images within the android application. For image picking, android applications use intent within the android application. In this article, we will take a look at How to implement Photo Picker in Android 13. A sample video is given below to get an idea about what we are going to do in this article.

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 Kotlin as the programming language.

Step 2: Updating SDK version in build.gradle file

Navigate to Gradle Scripts>module level build.gradle file and add change compile sdk and target sdk to 33. After that simply sync your project to install it. 

Step 3: 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. Comments are added inside the code to understand the code in more detail.


<?xml version="1.0" encoding="utf-8"?>
    <!--creating image view on below line-->
        android:layout_margin="10dp" />
    <!--creating button on below line to pick image-->
        android:text="Pick Image"
        app:backgroundTint="@color/edt_back_color" />

Step 4: Working with the MainActivity.kt file

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.


package com.example.gptapp
import android.R.attr
import android.content.Intent
import android.os.Bundle
import android.provider.MediaStore
import android.widget.Button
import android.widget.ImageView
class MainActivity : AppCompatActivity() {
    // creating variables on below line.
    lateinit var pickImageBtn: Button
    lateinit var imageIV: ImageView
    override fun onCreate(savedInstanceState: Bundle?) {
        // initializing variables on below line.
        pickImageBtn = findViewById(
        imageIV = findViewById(
        // adding click listener for button on below line.
        pickImageBtn.setOnClickListener {
            // calling intent on below line.
            val intent = Intent(MediaStore.ACTION_PICK_IMAGES)
            // starting activity on below line.
            startActivityForResult(intent, 1)
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode === RESULT_OK) {
            // compare the resultCode with the
            // constant
            if (requestCode === 1) {
                // Get the url of the image from data
                val selectedImageUri: Uri = data?.data!!
                if (null != selectedImageUri) {
                    // update the image view in the layout

Now run your application to see the output of it. 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!