Camera2 애플리케이션은 Camera2 API를 통해 확장 프로그램을 사용할 수 있습니다. 카메라2
API는 사용 가능한 확장 프로그램을 쿼리하고 확장 프로그램을 구성하는 방법을 제공합니다.
카메라 세션을 업데이트하고, 카메라 확장 프로그램 OEM 라이브러리와 통신할 수 있습니다. 이
를 사용하면 애플리케이션이 야간, HDR, 자동, 빛망울 효과 또는
얼굴 보정을 탭합니다.
Camera2 Extensions API 호환성을 위해 카메라 기기 테스트
다음 코드 스니펫은 기기가 Camera2를 지원하는지 확인합니다.
확장 프로그램 API. 일부 기기에서는 확장 프로그램이 지원되지 않거나 기기에서 하위 집합을 지원할 수 있습니다.
확장 프로그램 중 하나입니다. 이 스니펫은 호환되는 카메라 ID 목록을 반환하며
카메라 확장 프로그램
Camera2 Extensions API로 CameraExtensionSession 만들기
Camera2 Extensions API를 호환되는 기기에서 사용하는 경우
특정 카메라 확장 프로그램을 사용할 수 있습니다. 다음 코드 스니펫은
CameraExtensionSession 만드는 방법
기존 Camera2 애플리케이션에 야간 캡처 모드를 사용할 수 있습니다.
Kotlin
privatevalcaptureCallbacks=object:CameraExtensionSession.ExtensionCaptureCallback(){// Implement Capture Callbacks}privatevalextensionSessionStateCallback=object:CameraExtensionSession.StateCallback(){overridefunonConfigured(session:CameraExtensionSession){cameraExtensionSession=sessiontry{valcaptureRequest=cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW).apply{addTarget(previewSurface)}.build()session.setRepeatingRequest(captureRequest,Dispatchers.IO.asExecutor(),captureCallbacks)}catch(e:CameraAccessException){Snackbar.make(previewView,"Failed to preview capture request",Snackbar.LENGTH_SHORT).show()requireActivity().finish()}}overridefunonClosed(session:CameraExtensionSession){super.onClosed(session)cameraDevice.close()}overridefunonConfigureFailed(session:CameraExtensionSession){Snackbar.make(previewView,"Failed to start camera extension preview",Snackbar.LENGTH_SHORT).show()requireActivity().finish()}}privatefunstartExtensionSession(){valoutputConfig=arrayListOf(OutputConfiguration(stillImageReader.surface),OutputConfiguration(previewSurface))valextensionConfiguration=ExtensionSessionConfiguration(CameraExtensionCharacteristics.EXTENSION_NIGHT,outputConfig,Dispatchers.IO.asExecutor(),extensionSessionStateCallback)cameraDevice.createExtensionSession(extensionConfiguration)}
Java
privateCameraExtensionSession.ExtensionCaptureCallbackcaptureCallbacks=newCameraExtensionSession.ExtensionCaptureCallback(){// Implement Capture Callbacks};privateCameraExtensionSession.StateCallbackextensionSessionStateCallback=newCameraExtensionSession.StateCallback(){@OverridepublicvoidonConfigured(@NonNullCameraExtensionSessionsession){cameraExtensionSession=session;try{CaptureRequest.BuildercaptureRequestBuilder=cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);captureRequestBuilder.addTarget(previewSurface);CaptureRequestcaptureRequest=captureRequestBuilder.build();session.setRepeatingRequest(captureRequest,backgroundExecutor,captureCallbacks);}catch(CameraAccessExceptione){Snackbar.make(previewView,"Failed to preview capture request",Snackbar.LENGTH_SHORT).show();requireActivity().finish();}}@OverridepublicvoidonClosed(@NonNullCameraExtensionSessionsession){super.onClosed(session);cameraDevice.close();}@OverridepublicvoidonConfigureFailed(@NonNullCameraExtensionSessionsession){Snackbar.make(previewView,"Failed to start camera extension preview",Snackbar.LENGTH_SHORT).show();requireActivity().finish();}};privatevoidstartExtensionSession(){ArrayList<OutputConfiguration>outputConfig=newArrayList<>();outputConfig.add(newOutputConfiguration(stillImageReader.getSurface()));outputConfig.add(newOutputConfiguration(previewSurface));ExtensionSessionConfigurationextensionConfiguration=newExtensionSessionConfiguration(CameraExtensionCharacteristics.EXTENSION_NIGHT,outputConfig,backgroundExecutor,extensionSessionStateCallback);}
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Camera2 Extensions API\n\n**Note:** This page refers to the [Camera2](/reference/android/hardware/camera2/package-summary) package. Unless your app requires specific, low-level features from Camera2, we recommend using [CameraX](/camerax). Both CameraX and Camera2 support Android 5.0 (API level 21) and higher.\n\n\u003cbr /\u003e\n\nCamera2 provides an Extensions API for accessing [extensions](/training/camera/camera-extensions) that device manufacturers have implemented on various Android devices. For a list of supported extension modes, see [Camera extensions](/training/camera/camera-extensions).\n\nFor a list of devices that support extensions, see [Supported devices](/training/camera/supported-devices).\n\nExtensions architecture\n-----------------------\n\nThe following image shows the camera extensions architecture.\n**Figure 1.**Camera Extensions architecture\n\nA Camera2 application can use extensions through the Camera2 API. The Camera2\nAPI provides ways to query for available extensions, configure an extension\ncamera session, and communicate with the Camera Extensions OEM library. This\nallows your application to use extensions like Night, HDR, Auto, Bokeh, or\nFace Retouch.\n\nTest a camera device for Camera2 Extensions API compatibility\n-------------------------------------------------------------\n\nThe following code snippet checks if the device supports the Camera2\nExtensions API. Extensions are not supported by all devices or the device might support a subset\nof extensions. The snippet returns a list of compatible camera IDs which support\ncamera extensions. \n\n### Kotlin\n\n```kotlin\nprivate fun getExtensionCameraIds(cameraManager: CameraManager): List\u003cString\u003e =\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.S) {\n cameraManager.cameraIdList.filter { cameraId -\u003e\n val characteristics = cameraManager.getCameraCharacteristics(cameraId)\n val extensionCharacteristics =\n cameraManager.getCameraExtensionCharacteristics(cameraId)\n val capabilities =\n characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)\n extensionCharacteristics.supportedExtensions.isNotEmpty() &&\n capabilities?.contains(\n CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE\n ) ?: false\n }\n } else emptyList()\n```\n\n### Java\n\n```java\nprivate List\u003cString\u003e getExtensionCameraIds(CameraManager cameraManager)\n throws CameraAccessException {\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.S) {\n return Arrays.stream(cameraManager.getCameraIdList()).filter(cameraId -\u003e {\n try {\n CameraCharacteristics characteristics =\n cameraManager.getCameraCharacteristics(cameraId);\n CameraExtensionCharacteristics extensionCharacteristics =\n cameraManager.getCameraExtensionCharacteristics(cameraId);\n IntStream capabilities =\n Arrays.stream(\n characteristics.get(\n CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES\n )\n );\n return !extensionCharacteristics.getSupportedExtensions().isEmpty() &&\n capabilities.anyMatch(capability -\u003e capability == CameraCharacteristics\n .REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE\n );\n } catch (CameraAccessException e) {\n throw new RuntimeException(e);\n }\n }).collect(Collectors.toList());\n } else {\n return Collections.emptyList();\n }\n}\n```\n\nCreate a CameraExtensionSession with the Camera2 Extensions API\n---------------------------------------------------------------\n\nThe Camera2 Extensions API, when used with compatible devices, lets you access\ncertain camera extensions. The following code snippet showcases an example of\nhow to create a [`CameraExtensionSession`](https://developer.android.com/reference/android/hardware/camera2/CameraExtensionSession)\nfor using night capture mode for an existing Camera2 application. \n\n### Kotlin\n\n```kotlin\nprivate val captureCallbacks = object : CameraExtensionSession.ExtensionCaptureCallback() {\n // Implement Capture Callbacks\n}\nprivate val extensionSessionStateCallback = object : CameraExtensionSession.StateCallback() {\n override fun onConfigured(session: CameraExtensionSession) {\n cameraExtensionSession = session\n try {\n val captureRequest =\n cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW).apply {\n addTarget(previewSurface)\n }.build()\n session.setRepeatingRequest(\n captureRequest,\n Dispatchers.IO.asExecutor(),\n captureCallbacks\n )\n } catch (e: CameraAccessException) {\n Snackbar.make(\n previewView,\n \"Failed to preview capture request\",\n Snackbar.LENGTH_SHORT\n ).show()\n requireActivity().finish()\n }\n }\n\n override fun onClosed(session: CameraExtensionSession) {\n super.onClosed(session)\n cameraDevice.close()\n }\n\n override fun onConfigureFailed(session: CameraExtensionSession) {\n Snackbar.make(\n previewView,\n \"Failed to start camera extension preview\",\n Snackbar.LENGTH_SHORT\n ).show()\n requireActivity().finish()\n }\n}\n\nprivate fun startExtensionSession() {\n val outputConfig = arrayListOf(\n OutputConfiguration(stillImageReader.surface),\n OutputConfiguration(previewSurface)\n )\n val extensionConfiguration = ExtensionSessionConfiguration(\n CameraExtensionCharacteristics.EXTENSION_NIGHT,\n outputConfig,\n Dispatchers.IO.asExecutor(),\n extensionSessionStateCallback\n )\n cameraDevice.createExtensionSession(extensionConfiguration)\n}\n```\n\n### Java\n\n```java\nprivate CameraExtensionSession.ExtensionCaptureCallback captureCallbacks =\n new CameraExtensionSession.ExtensionCaptureCallback() {\n // Implement Capture Callbacks\n };\n\nprivate CameraExtensionSession.StateCallback extensionSessionStateCallback =\n new CameraExtensionSession.StateCallback() {\n @Override\n public void onConfigured(@NonNull CameraExtensionSession session) {\n cameraExtensionSession = session;\n try {\n CaptureRequest.Builder captureRequestBuilder =\n cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);\n captureRequestBuilder.addTarget(previewSurface);\n CaptureRequest captureRequest = captureRequestBuilder.build();\n session.setRepeatingRequest(captureRequest, backgroundExecutor, captureCallbacks);\n } catch (CameraAccessException e) {\n Snackbar.make(\n previewView,\n \"Failed to preview capture request\",\n Snackbar.LENGTH_SHORT\n ).show();\n requireActivity().finish();\n }\n }\n\n @Override\n public void onClosed(@NonNull CameraExtensionSession session) {\n super.onClosed(session);\n cameraDevice.close();\n }\n\n @Override\n public void onConfigureFailed(@NonNull CameraExtensionSession session) {\n Snackbar.make(\n previewView,\n \"Failed to start camera extension preview\",\n Snackbar.LENGTH_SHORT\n ).show();\n requireActivity().finish();\n }\n };\n\nprivate void startExtensionSession() {\n ArrayList\u003cOutputConfiguration\u003e outputConfig = new ArrayList\u003c\u003e();\n outputConfig.add(new OutputConfiguration(stillImageReader.getSurface()));\n outputConfig.add(new OutputConfiguration(previewSurface));\n ExtensionSessionConfiguration extensionConfiguration = new ExtensionSessionConfiguration(\n CameraExtensionCharacteristics.EXTENSION_NIGHT,\n outputConfig,\n backgroundExecutor,\n extensionSessionStateCallback\n );\n}\n```\n\nAdditional resources\n--------------------\n\nFor more information, see\n[`CameraExtensionCharacteristics`](/reference/android/hardware/camera2/CameraExtensionCharacteristics)\nand view the public [Camera2 Extensions API samples](https://github.com/android/camera-samples/tree/master/Camera2Extensions)\nfor more."]]