Friday 1 April 2016

HB Blog 107: Android Camera Using Intents And Custom Interface.

Android, Inc. was founded in Palo Alto, California in October 2003 by Andy Rubin (co-founder of Danger), Rich Miner (co-founder of Wildfire Communications, Inc.), Nick Sears (once VP at T-Mobile), and Chris White (headed design and interface development at WebTV) to develop, in Rubin's words, "smarter mobile devices that are more aware of its owner's location and preferences". The early intentions of the company were to develop an advanced operating system for digital cameras. Though, when it was realized that the market for the devices was not large enough, the company diverted its efforts toward producing a smartphone operating system.

The Android framework includes support for various cameras and camera features available on devices, allowing you to capture pictures and videos in your applications. We can develop camera applications using existing camera as well as create our own custom camera based on the requirement of the application.
Using Existing Camera Apps: -
We can use basic intents to start to invoke an existing Android camera application. A camera intent makes a request to capture a picture or video clip through an existing camera app and then returns control back to your application.

The procedure for invoking a camera intent follows these general steps:
    Compose a Camera Intent - Create an Intent that requests an image, using one of these intent types:
     MediaStore.ACTION_IMAGE_CAPTURE - Intent action type for requesting an image from an existing camera application.
    Start the Camera Intent - Use the startActivityForResult() method to execute the camera intent. After you start the intent, the Camera application user interface appears on the device screen and the user can take a picture or video.
    Receive the Intent Result - Set up an onActivityResult() method in your application to receive the callback and data from the camera intent. When the user finishes taking a picture or video (or cancels the operation), the system calls this method.

Building a Camera App: -
Creating custom camera is not as simple as calling intent and few lines of code.

The general steps for creating a custom camera interface for your application are as follows:
    Detect and Access Camera - Create code to check for the existence of cameras and request access.
    Create a Preview Class - Create a camera preview class that extends SurfaceView and implements the SurfaceHolder interface. This class previews the live images from the camera.
    Build a Preview Layout - Once you have the camera preview class, create a view layout that incorporates the preview and the user interface controls you want.
    Setup Listeners for Capture - Connect listeners for your interface controls to start image or video capture in response to user actions, such as pressing a button.
    Capture and Save Files - Setup the code for capturing pictures or videos and saving the output.
    Release the Camera - After using the camera, your application must properly release it for use by other applications.

No comments:

Post a Comment