MyAd

Thursday 19 October 2017

Custom Android Camera in Android Studio using Camera2 API

Custom Camera API Tutorial in Android Studio using Camera2 API

Welcome guys. So in this tutorial you will learn how to display the camera preview in your Android Application. So lets get started.

Introduction

Nowadays a lot of apps offer users to take pictures and record videos for various kind of purposes. In this tutorial you will learn how to do the same in your android application. You can integrate your camera in multiple ways. One of the most simple way is to use the built-in camera app of Android. This is a simple process where you just call your built-in camera application using intent and you just take picture and videos from it and save them in your android directory. This way of accessing camera wont give you much control over your camera in certain ways as most of the work is done by the built-in camera app. This way is most appropriate when you just want to take a picture and video. The second step is to use the Custom camera app in your android and then add the camera functionality on your own. So this way will require you more effort because all of the background work and most of the work will be done by the developer. Building custom Camera interface will be useful when you are building an application which mainly deals with images and videos just like Instagram app.

Source Code

First of all you have to specify the permissions which your app will be requiring when it will be installed on your android smartphone. So open AndroidManifest.xml and add these lines of code in the beginning. Now create your activity_main.xml and change the Layout to FrameLayout. Now add the following code in your MainActivity.java.





So the complete switch_on_camera() method will be like this:





So now you have to create another class ShowCamera and extend it with SurfaceView.


3 comments:

  1. Your source code lacks more info! A total wrekt noob like me who just graduated from high scool finds hard to follow which seems basic to you or other pro-Programmers! (I need imports! etc.) a .zip would be blessful!

    ReplyDelete
  2. So, where is the source code?

    ReplyDelete

Decompile any APK to get Source Code

In this video I will teach you how to compile any APK file to decompile and get the source code of any android app using Android Studio....