Guides

Android Studio Tutorial – Camera 2 API FULL



Facebook : http://facebook.com/edmtdev
Link donate : http://paypal.me/edmtdev

Link source code : http://ceesty.com/wMz75X

In this tutorial, we are going to learn how to implement android camera 2 API. This example tutorial will focus on the new android camera api, if you are looking for the old camera api then I will suggest you read my previous tutorial on android camera api tutorial.

If you have worked with android camera before and then you want to try your hand in android camera2 API introduce in android API level 21 you will understand how difficult it is to understand how to use and implement android camera2 api in your app.

It replaces the deprecated Camera class

android development tutorial,android programming tutorial,android app development tutorial,android tutorial for beginners,android app tutoria,android studio tutorial,learn android programming,android developer tutorial,android programming,android development,android studio tutorial for beginners,android course,android training,android development course,android app development course

38 Comments

  • Chung Yau Ong

    Hi, is the library able to set a fixed focus value? something like this in other video @NyT0 (@ – @).Instead of using sliding bar to set focus value, I want to use a hard coded value to set focus.

  • Gaurav Joshi

    Hello eddydn,
    thanks for the video…
    could you tell us how to improve the resolution of the preview as well as the images stored…
    awaiting your new Camera2 tutorials…

  • Karan Jatav

    It is 2019 and the world has reached new heights but you waste time typing and switching between editors.

  • Hạng A Tính

    I reported an error here: cameraCaptureSession.capture (captureBuilder.build (), captureListener, mBackgroundHandler);

  • Oscar Vallarino

    Class requires API level 21 (current min is 15) but:

    compileSdkVersion 28
    minSdkVersion 15
    targetSdkVersion 28

    Any ideas?

  • Kevin Livingstone

    Is there a code listing? every time i go to the link in the description, it takes me basically malware, and downloads that i don't want

  • Ronny Liem

    How to capture camera automatic without user click? And upload to storage server ? I want to make app prank to my friend :v ?

  • Dipanshu Kapoor

    I am getting this exception while capturing the image

    E/AndroidRuntime: FATAL EXCEPTION: Camera Background
    Process: com.imperialsoupgmail.tesseractexample, PID: 23717
    java.lang.IllegalStateException: Session has been closed; further changes are illegal.
    at android.hardware.camera2.impl.CameraCaptureSessionImpl.checkNotClosed(CameraCaptureSessionImpl.java:834)
    at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:164)
    at com.imperialsoupgmail.tesseractexample.MainActivity$5.onConfigured(MainActivity.java:298)
    at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy.lambda$onConfigured$0(CallbackProxies.java:53)
    at android.hardware.camera2.impl.-$$Lambda$CallbackProxies$SessionStateCallbackProxy$soW0qC12Osypoky6AfL3P2-TeDw.run(Unknown Source:4)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.os.HandlerThread.run(HandlerThread.java:65)
    I/Process: Sending signal. PID: 23717 SIG: 9
    Application terminated.

  • An Drew

    Since I start app camera doesn't show, but when i lock ant then unlock phone – camera shows. How can I fixed this problem?

  • R.J

    please give the source code link ….. source code link expired

    please…………………………..give the link

  • siraY

    Hello, I'm experiencing the current issue

    E/AndroidRuntime: FATAL EXCEPTION: Camera Background

    Process: com.example.android.ucheck, PID: 5648

    java.lang.IllegalStateException: Session has been closed; further changes are illegal.

    at android.hardware.camera2.impl.CameraCaptureSessionImpl.checkNotClosed(CameraCaptureSessionImpl.java:835)

    at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:164)

    at com.example.android.ucheck.Camera2$5.onConfigured(Camera2.java:204)

    at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy.lambda$onConfigured$0(CallbackProxies.java:53)

    at android.hardware.camera2.impl.-$$Lambda$CallbackProxies$SessionStateCallbackProxy$soW0qC12Osypoky6AfL3P2-TeDw.run(Unknown Source:4)

    at android.os.Handler.handleCallback(Handler.java:891)

    at android.os.Handler.dispatchMessage(Handler.java:102)

    at android.os.Looper.loop(Looper.java:207)

    at android.os.HandlerThread.run(HandlerThread.java:65)

    Would you know the possible solution to this issue?

  • Abhishek Nayak

    I am having this exception "android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): submitRequestList – cannot use a surface that wasn't configured" while capturing the image

  • Shashank A.C

    I tried rotating the phone by 90 degrees and noticed that the camera is showing everything rotated by 90 degrees.
    I paste the error in the logs here.

    02-25 10:31:41.277 22329-22329/com.example.androidcamera2api I/CameraManager: Using legacy camera HAL.
    02-25 10:31:41.281 22329-22702/com.example.androidcamera2api E/Camera: Error 2
    02-25 10:31:41.281 22329-22702/com.example.androidcamera2api I/RequestThread-0: Flushing all pending requests.
    02-25 10:31:41.281 22329-22702/com.example.androidcamera2api I/RequestQueue: Repeating capture request cancelled.
    02-25 10:31:41.281 22329-22702/com.example.androidcamera2api W/RequestHolder: Capture failed for request: 0
    02-25 10:31:41.281 22329-22702/com.example.androidcamera2api I/CameraDeviceState: Legacy camera service transitioning to state ERROR
    02-25 10:31:41.284 22329-22758/com.example.androidcamera2api I/CameraDeviceState: Legacy camera service transitioning to state IDLE
    02-25 10:31:41.284 22329-22758/com.example.androidcamera2api E/CameraDeviceState: Cannot call idle while in state: 0
    02-25 10:31:41.626 22329-22329/com.example.androidcamera2api E/RequestQueue: cancel failed: no repeating request exists for request id: 0

  • Yudi Karma

    please set camera in landscape then go lock screen with password then unlock screen and will go back to camera activity in landscape. do you have error in thats ? i get error in redmi note 3 running android v 22

  • NamJin Shipper's Club

    please help how to make burst mode by camera2? please answer me i will pay 20 dollars who give me code of it

  • Cordis Die

    it works good, however, i have a problem with the resolution, it uses only 240×320. Is there anything i am doing wrong?

  • Yudi Karma

    have issue when capture image in landscape mode, thats make image capture different with preview
    this is my ask stackoverflow

    https://stackoverflow.com/questions/53927058/camera2-capture-image-different-with-preview

  • Talib Zaidi

    application is showing preview, but when i click on capture button, preview get stuck, but nothing is saved and toast doesn't show up

  • Austin Hatherly

    love the very little explanation on what anything is or how it works or the fact that the link to the source code is so infested by ads you can't actually get to it. The fact that half of the variables he's typing in aren't initialized prior to making them for example textureView, view or .getId and the list goes on wich results in a few paragraphs of code that more holes in it than a peg board but hey on the bright side it's better than the legit android developer website that just provides a basic explanation that you can't fully understand because there's so many technical terms it makes your head spin and when you try to find out what they mean it sends you down a rabbit hole that takes hours to figure out. and if you try to get the online coding classes from google udacity it's so outdated it provides little to no help especially with something like this. it's not this dudes fault just as a new guy to the world of coding it's really frustrating

  • Amol Gaikwad

    Please make video on how to add watermark including (date time and name) in camera app ?
    Hit like who's want video on this topic

  • Ajai Kumar

    When camera is in light it should not flash and I want to keep flash always on when camera goes dark. what is the API for that ?

  • Mukesh Pokharel

    Hello.. I exactly copied your code…… ..everything works fine. Only problem is that I cannot see what I am capturing.. I mean Camera doesn't open. But when I go to the SD card, I can see the captured image. …. So I want to know how can I call this activity from another activity so that I can see people or the scenarios behind the camera. But I cannot see what image I am clicking. The screen comes plain white. However, the image gets stored. Thank You.

  • Amila Abeygunasekara

    Great tutorial! Camera preview working perfectly. But unfortunately when I press capture button the preview get stuck.
    Here is the logcat:
    -14002/imagedumpingapp W/CameraDevice-JV-0: Stream configuration failed due to: endConfigure:380: Camera 0: Unsupported set of inputs/outputs provided
    09-10 02:22:22.423 14002-14002/imagedumpingapp E/CameraCaptureSession: Session 1: Failed to create capture session; configuration failed
    09-10 02:22:22.424 14002-14015/imagedumpingapp W/zygote64: Long monitor contention with owner main (14002) at boolean android.os.BinderProxy.transactNative(int, android.os.Parcel, android.os.Parcel, int)(Binder.java:-2) waiters=0 in void android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onResultReceived(android.hardware.camera2.impl.CameraMetadataNative, android.hardware.camera2.impl.CaptureResultExtras) for 198ms

  • Selçuk Savaş

    It works on Nexus 5X Emulator (Android 8.0.0 API 26). But It doesn't work on my device.(Android 8.0.0 API 26). What must I do?

Leave a Reply

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