README.md
1Android Camera2Basic Sample
2===================================
3
4This sample demonstrates how to use basic functionalities of Camera2
5API. You can learn how to iterate through characteristics of all the
6cameras attached to the device, display a camera preview, and take
7pictures.
8
9Introduction
10------------
11
12The [Camera2 API][1] provides an interface to individual camera
13devices connected to an Android device. It replaces the deprecated
14Camera class.
15
16Use [getCameraIdList][2] to get a list of all the available
17cameras. You can then use [getCameraCharacteristics][3] and find the
18best camera that suits your need (front/rear facing, resolution etc).
19
20Create an instance of [CameraDevice.StateCallback][4] and open a
21camera. It is ready to start camera preview when the camera is opened.
22
23This sample uses TextureView to show the camera preview. Create a
24[CameraCaptureSession][5] and set a repeating [CaptureRequest][6] to it.
25
26Still image capture takes several steps. First, you need to lock the
27focus of the camera by updating the CaptureRequest for the camera
28preview. Then, in a similar way, you need to run a precapture
29sequence. After that, it is ready to capture a picture. Create a new
30CaptureRequest and call [capture][7]. Don't forget to unlock the focus
31when you are done.
32
33[1]: https://developer.android.com/reference/android/hardware/camera2/package-summary.html
34[2]: https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraIdList()
35[3]: https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraCharacteristics(java.lang.String)
36[4]: https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html
37[5]: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html
38[6]: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html
39[7]: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler)
40
41Pre-requisites
42--------------
43
44- Android SDK v21
45- Android Build Tools v21.1.1
46- Android Support Repository
47
48Screenshots
49-------------
50
51<img src="screenshots/main.png" height="400" alt="Screenshot"/>
52
53Getting Started
54---------------
55
56This sample uses the Gradle build system. To build this project, use the
57"gradlew build" command or use "Import Project" in Android Studio.
58
59Support
60-------
61
62- Google+ Community: https://plus.google.com/communities/105153134372062985968
63- Stack Overflow: http://stackoverflow.com/questions/tagged/android
64
65If you've found an error in this sample, please file an issue:
66https://github.com/googlesamples/android-Camera2Basic
67
68Patches are encouraged, and may be submitted by forking this project and
69submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
70
71License
72-------
73
74Copyright 2014 The Android Open Source Project, Inc.
75
76Licensed to the Apache Software Foundation (ASF) under one or more contributor
77license agreements. See the NOTICE file distributed with this work for
78additional information regarding copyright ownership. The ASF licenses this
79file to you under the Apache License, Version 2.0 (the "License"); you may not
80use this file except in compliance with the License. You may obtain a copy of
81the License at
82
83http://www.apache.org/licenses/LICENSE-2.0
84
85Unless required by applicable law or agreed to in writing, software
86distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
87WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
88License for the specific language governing permissions and limitations under
89the License.
90