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