Pick Image From Gallery Or Camera In Android Kotlin Programmatically

Pick image from gallery or camera in android kotlin example is today’s tutorial.

Pick image from gallery or camera in android kotlin tutorial guides you how to select/get the image from a gallery in android programmatically.

We will choose/take a photo from gallery or camera in the Android Studio by opening via Intent.

First, check the output of pick image from gallery or camera in android example and then we will develop it.

Creating Pick Image From Gallery Or Camera In Android Studio Tutorial step by step

Step 1: Create a new project in Android Studio.

Step 2: Updating AndroidManifest.xml file

 add required permissions between <manifest>….</manifest> tag.

Note: If you are targeting SDK version above 22 (Above Lollipop)  then you need to ask a user for granting runtime permissions. Check marshmallow runtime permission for more information.

Final code for AndroidManifest.xml file

Step 3: Updating activity_main.xml file

 Copy and paste below source code in activity_main.xml file

Step 4: Preparing MainActivity.java class

Add following source code in MainActivity.java class

Step 5: Description of MainActivity.java

When the user clicks the button, dialog with select options appears.

Following is button click method.

The dialog contains options whether to select an image from gallery or to capture from camera.

Below is the code for showPictureDialog() method.

If a user selects gallery, then following method is executed.

And if user choose camera, then below method is run.

After selecting an image from gallery or capturing photo from camera, an onActivityResult() method is executed.

Code for onActivityResult(), is as below.

If an image comes from an gallery, then compiler goes at below code.

If a photo is from a camera, then compiler goes to following.

Below is the method to save the image or photo.

In above code, IMAGE_DIRECTORY is the folder name in which all the images will be saved.

JAVA Version

Java version of this tutorial : Get Image From Gallery Android

Other information regarding this tutorial

So that’s all for pick image from gallery or camera in android kotlin example. If you have queries, then ask them in the comment section. Thank you 🙂

Download Source Code

[sociallocker]Download KotlinSelectImageGallery[/sociallocker]

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

14 Responses

  1. manish says:

    thanks for the help, it saves my lot of time

  2. German says:

    Step 3 is not showed, is missing a part of the tutorial?


    Thank you very much for the information, it was the code that I understood the most.

  4. AKASH STARVIN says:

    It shows the following error
    at com.example.android.cameratogallery.MainActivity.takePhotoFromCamera(MainActivity.kt:63)

    private fun takePhotoFromCamera() {
    val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
    startActivityForResult(intent, CAMERA) // line 66

  5. AKASH STARVIN says:

    Image clicked by that app is of very low quality, how to improve the quality?
    How to get those images in list view ?
    Thank you…

  6. wei bing says:

    can it store multiple image?

  7. Lucas says:

    Where is the step 3?

Leave a Reply

Your email address will not be published. Required fields are marked *