# Using OzCapsula Data Container in Native SDK

OzCapsula is our proprietary data format, designed to provide end-to-end protection and maintain data integrity during transmission. We've introduced this format in 8.22 and implemented new methods to use it:

* `createMediaCaptureScreen(request)` for video capture: this method takes a video and packages it into a data container.
* `AnalysisRequest.addContainer` for processing data: this method adds container to the analysis request.

## Code Examples

Please follow the links below to access the examples. You can also refer to the illustrative examples shown below the links.

* [Kotlin](https://gitlab.com/oz-forensics/oz-liveness-android/-/blob/master/sample-kotlin/src/main/java/com/ozforensics/liveness/sample/LivenessContainerActivity.kt)
* [Java](https://gitlab.com/oz-forensics/oz-liveness-android/-/blob/master/sample-java/src/main/java/com/ozforensics/liveness/sample/LivenessContainerActivity.java)
* [Swift](https://gitlab.com/oz-forensics/public/oz-liveness-ios-sample/-/blob/main/OZLiveness/DataContainerViewController.swift?ref_type=heads)

### **Kotlin**

```kotlin
// capture and pack media
val referentPhoto = MediaRequest.UserMedia(OzAbstractMedia.OzDocumentPhoto(OzMediaTag.Blank, referentPhotoPath))
val blinkVideo = MediaRequest.ActionMedia(OzAction.EyeBlink)
val scanVideo = MediaRequest.ActionMedia(OzAction.Scan)

val intent = OzLivenessSDK.createMediaCaptureScreen(
    CaptureRequest(
        listOf(
            AnalysisProfile(
                Analysis.Type.BIOMETRY,
                listOf(referentPhoto, scanVideo)
            ),
            AnalysisProfile(
                Analysis.Type.QUALITY,
                listOf(referentPhoto, scanVideo, blinkVideo)
            ),
        ),
    ),
    sessionToken
)
startActivityForResult(intent, REQUEST_CODE_SDK)

// subscription to result
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == REQUEST_CODE_SDK) {
        when (resultCode) {
            OzLivenessResultCode.USER_CLOSED_LIVENESS -> { /* user closed the screen */ }
            OzLivenessResultCode.SUCCESS -> {
            // result
                val container = OzLivenessSDK.getContainerFromIntent(data)
                ...
            }
            else -> {
            // error
                val errorMessage = OzLivenessSDK.getErrorFromIntent(data)
                ...
            }
        }
    }
}

// launching analyses
AnalysisRequest.Builder()
    .addContainer(container)
    .build()
    .run(
        object: AnalysisRequest.AnalysisListener {
            override fun onSuccess(result: RequestResult) {
                ...
            }
            override fun onError(exception: OzException) {
                ...
            }
        }
    )
```

### **Swift**

```swift
// capture and pack media
let mediaRequest = MediaRequest.actionMedia(.selfie)
let profile = AnalysisProfile(mediaList: [mediaRequest],
                           type: .quality,
                           params: ["extract_best_shot" : true])
             
let request = CaptureRequest(analysisProfileList: [profile], cameraPosition: cameraPosition)
self.ozLivenessVC = try OZSDK.createMediaCaptureScreen(self, request, sessionToken: sessionToken)
self.present(ozLivenessVC, animated: true)

// subscription to result
extension ViewController: LivenessDelegate {
   
  func onError(status: OZVerificationStatus?) {
      // error handling
  }
   
  func onResult(container: DataContainer) {
    let analysisRequest = AnalysisRequestBuilder()
    analysisRequest.addContainer(container)
     
    analysisRequest.run(statusHandler: { [weak self] state in
     },
              errorHandler: { [weak self] error in
     // error
    }) { result in
// result
        }
   }

```

## Methods and Properties

Please check the methods and properties below. You can also find them in the corresponding sections of [iOS](/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/ios/ios-sdk-methods-and-properties.md#data-container) and [Android](/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/android/android-sdk-methods-and-properties.md#data-container) documentation sections.

#### addContainer

This method replaces `addAnalysis` in the `AnalysisRequest` structure when you use the data container flow.

**Input**

|                 |              |                                                                                                                                        |
| --------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
| **Parameter**   | **Type**     | **Description**                                                                                                                        |
| OzDataContainer | bytearray\[] | An encrypted file containing media and collateral info, the output of the [createMediaCaptureScreen](#createmediacapturescreen) method |

#### createMediaCaptureScreen

Captures media file with all information you need and packages it into a data container.

**Input**

| **Parameter**  | **Type**                                            | **Description**                     |
| -------------- | --------------------------------------------------- | ----------------------------------- |
| request        | [CaptureRequest](#public-data-class-capturerequest) | Detects a request for video capture |
| session\_token | String                                              | Token for current session           |

**Output**

| **Parameter**   | **Type**     | **Description**                                        |
| --------------- | ------------ | ------------------------------------------------------ |
| OzDataContainer | bytearray\[] | An encrypted file containing media and collateral info |

#### public data class CaptureRequest

Detects a request for video capture.

| **Parameter**                  | **Type**                                                    | **Description**                                                                                 |
| ------------------------------ | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| analysisProfileList            | List<[AnalysisProfile](#public-data-class-analysisprofile)> | A list of objects that contain information on media and analyses that should be applied to them |
| folderMeta (optional)          | Map\<String, Any>                                           | Additional folder metadata                                                                      |
| additionalMediaList (optional) | List<[MediaRequest](#public-sealed-class-mediarequest)>     | Media files that you need to upload to server, but it’s not necessary for analyses              |
| cameraPosition (optional)      | String                                                      | <p><code>front</code> (default) – front camera</p><p><code>back</code> – rear camera</p>        |

#### public data class AnalysisProfile

Contains information on media files and analyses that should be applied to them.

| **Parameter**     | **Type**                                                                                                                                                                                                                                                                                                   | **Description**                |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
| mediaList         | List<[MediaRequest](#public-sealed-class-mediarequest)>                                                                                                                                                                                                                                                    | A list of media to be analyzed |
| type              | String ([Type](https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/pages/VCUMVrFbFl9Y2E7Flmdx#h.fr9jc6r5rcc) (Android) or [AnalysisType](https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/pages/BVX89LL3HSWuDVvGUadK#h.qww0i8kvhvdr) (iOS)) | Analysis type                  |
| params (optional) | Map\<String, Any>                                                                                                                                                                                                                                                                                          | Additional analysis parameters |

#### public sealed class MediaRequest

Stores information about a media file.

{% hint style="warning" %}
Please note: you should add `actionMedia` OR `userMedia`, these parameters are mutually exclusive.
{% endhint %}

| Parameter   | Type                                                                                                                                                                                                                                                                                                             | Description                                                   |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| id          | String (UUID v4)                                                                                                                                                                                                                                                                                                 | Media ID                                                      |
| actionMedia | [OzAction](https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/pages/VCUMVrFbFl9Y2E7Flmdx#h.2nyke2meu4aw) (Android) or [OzVerificationMovemen](https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/pages/BVX89LL3HSWuDVvGUadK#h.20yp3ix24ijd)t (iOS) | An action that user should perform in a video                 |
| userMedia   | [OzAbstractMedia](https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/pages/VCUMVrFbFl9Y2E7Flmdx#h.s2ye0si7dzc2) (Android) or [OZMedia](https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/pages/BVX89LL3HSWuDVvGUadK#h.hizmhq9c5cq9) (iOS)         | An external media file, e.g., a reference or a document photo |

#### Exceptions

| **Error**                                                                                                                                           | **Text**                                                      | **Description**                                     |
| --------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | --------------------------------------------------- |
| session\_token\_is\_empty                                                                                                                           | Session token must not be empty                               | Session token is mandatory but hasn’t been provided |
| data\_container\_internal\_failure\_1                                                                                                               | Internal failure occurred while processing the data container | The device doesn’t have enough memory to proceed    |
| <ul><li>data\_container\_internal\_failure\_2</li><li>data\_container\_internal\_failure\_3</li><li>data\_container\_internal\_failure\_4</li></ul> | Internal failure occurred while processing the data container | SDK couldn’t generate the container. Try again      |
| data\_container\_internal\_failure\_1000                                                                                                            | Internal failure occurred while processing the data container | Any other error not from the list above             |

If, during the video capture, SDK encounters an error that prevents user scenario from completion, the data container is deleted.

Should you have any questions, please contact us.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.ozforensics.com/oz-knowledge/guides/developer-guide/sdk/oz-mobile-sdk/using-ozcapsula-data-container-in-native-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
