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 <minSdk>21</minSdk> 25 <compileSdkVersion>21</compileSdkVersion> 26 <strings> 27 <intro> 28 <![CDATA[ 29 This sample demonstrates the basic use of Camera2 API. Check the source code to see how 30 you can display camera preview and take pictures. 31 ]]> 32 </intro> 33 </strings> 34 35 <template src="base"/> 36 37 <metadata> 38 <status>PUBLISHED</status> 39 <categories>Media, Camera, Camera2</categories> 40 <technologies>Android</technologies> 41 <languages>Java</languages> 42 <solutions>Mobile</solutions> 43 <level>INTERMEDIATE</level> 44 <icon>screenshots/icon-web.png</icon> 45 <screenshots> 46 <img>screenshots/main.png</img> 47 </screenshots> 48 <api_refs> 49 <android>android.hardware.camera2.CameraManager</android> 50 <android>android.hardware.camera2.CameraDevice</android> 51 <android>android.hardware.camera2.CameraCharacteristics</android> 52 <android>android.hardware.camera2.CameraCaptureSession</android> 53 <android>android.hardware.camera2.CaptureRequest</android> 54 <android>android.hardware.camera2.CaptureResult</android> 55 <android>android.view.TextureView</android> 56 </api_refs> 57 58 <description> 59 <![CDATA[ 60 This sample demonstrates how to use basic functionalities of Camera2 61 API. You can learn how to iterate through characteristics of all the 62 cameras attached to the device, display a camera preview, and take 63 pictures. 64 ]]> 65 </description> 66 67 <intro> 68 <![CDATA[ 69 The [Camera2 API][1] provides an interface to individual camera 70 devices connected to an Android device. It replaces the deprecated 71 Camera class. 72 73 Use [getCameraIdList][2] to get a list of all the available 74 cameras. You can then use [getCameraCharacteristics][3] and find the 75 best camera that suits your need (front/rear facing, resolution etc). 76 77 Create an instance of [CameraDevice.StateCallback][4] and open a 78 camera. It is ready to start camera preview when the camera is opened. 79 80 This sample uses TextureView to show the camera preview. Create a 81 [CameraCaptureSession][5] and set a repeating [CaptureRequest][6] to it. 82 83 Still image capture takes several steps. First, you need to lock the 84 focus of the camera by updating the CaptureRequest for the camera 85 preview. Then, in a similar way, you need to run a precapture 86 sequence. After that, it is ready to capture a picture. Create a new 87 CaptureRequest and call [capture][7]. Don't forget to unlock the focus 88 when you are done. 89 90 [1]: https://developer.android.com/reference/android/hardware/camera2/package-summary.html 91 [2]: https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraIdList() 92 [3]: https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraCharacteristics(java.lang.String) 93 [4]: https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html 94 [5]: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html 95 [6]: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html 96 [7]: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler) 97 ]]> 98 </intro> 99 </metadata> 100 101 </sample> 102