1<?xml version="1.0" encoding="UTF-8"?> 2<!-- 3 Copyright 2014 The Android Open Source Project 4 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, software 12 distributed under the License is distributed on an "AS IS" BASIS, 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 See the License for the specific language governing permissions and 15 limitations under the License. 16--> 17 18 19 20<sample> 21 <name>Camera2Basic</name> 22 <group>Media</group> 23 <package>com.example.android.camera2basic</package> 24 25 <dependency>com.android.support:appcompat-v7:23.0.0</dependency> 26 <minSdk>21</minSdk> 27 <strings> 28 <intro> 29 <![CDATA[ 30 This sample demonstrates the basic use of Camera2 API. Check the source code to see how 31 you can display camera preview and take pictures. 32 ]]> 33 </intro> 34 </strings> 35 36 <template src="base"/> 37 38 <metadata> 39 <status>PUBLISHED</status> 40 <categories>Media, Camera, Camera2</categories> 41 <technologies>Android</technologies> 42 <languages>Java</languages> 43 <solutions>Mobile</solutions> 44 <level>INTERMEDIATE</level> 45 <icon>screenshots/icon-web.png</icon> 46 <screenshots> 47 <img>screenshots/main.png</img> 48 </screenshots> 49 <api_refs> 50 <android>android.hardware.camera2.CameraManager</android> 51 <android>android.hardware.camera2.CameraDevice</android> 52 <android>android.hardware.camera2.CameraCharacteristics</android> 53 <android>android.hardware.camera2.CameraCaptureSession</android> 54 <android>android.hardware.camera2.CaptureRequest</android> 55 <android>android.hardware.camera2.CaptureResult</android> 56 <android>android.view.TextureView</android> 57 </api_refs> 58 59 <description> 60<![CDATA[ 61This sample demonstrates how to use basic functionalities of Camera2 62API. You can learn how to iterate through characteristics of all the 63cameras attached to the device, display a camera preview, and take 64pictures. 65]]> 66 </description> 67 68 <intro> 69<![CDATA[ 70The [Camera2 API][1] provides an interface to individual camera 71devices connected to an Android device. It replaces the deprecated 72Camera class. 73 74Use [getCameraIdList][2] to get a list of all the available 75cameras. You can then use [getCameraCharacteristics][3] and find the 76best camera that suits your need (front/rear facing, resolution etc). 77 78Create an instance of [CameraDevice.StateCallback][4] and open a 79camera. It is ready to start camera preview when the camera is opened. 80 81This sample uses TextureView to show the camera preview. Create a 82[CameraCaptureSession][5] and set a repeating [CaptureRequest][6] to it. 83 84Still image capture takes several steps. First, you need to lock the 85focus of the camera by updating the CaptureRequest for the camera 86preview. Then, in a similar way, you need to run a precapture 87sequence. After that, it is ready to capture a picture. Create a new 88CaptureRequest and call [capture][7]. Don't forget to unlock the focus 89when you are done. 90 91[1]: https://developer.android.com/reference/android/hardware/camera2/package-summary.html 92[2]: https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraIdList() 93[3]: https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraCharacteristics(java.lang.String) 94[4]: https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html 95[5]: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html 96[6]: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html 97[7]: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler) 98]]> 99 </intro> 100 </metadata> 101 102</sample> 103