---
description: With OCR
---

# Generate Liveness Surface

BiometridOn liveness detection surface acts on an isolated environment and its represented as a fragment that can be added on any activity.

In this particular case, the following method will allow the developer to generate a Fragment that contains our liveness engine ready to be used.

To generate the surface:

```java
BiometridOn.getInstance().generateLivenessWithOcrSurface(String token, StepType step_type, DocType, LivenessCustomisation customisation, ArrayList<String> files, Context context);
```

&#x20;The method will return a Fragment that the developer should implement using android's FragmentManager class. Be aware that if the liveness detection fails then no matching will be made and a new surface has to be generated.

Since the validation of the document takes longer than normal procedures, the developer has to wait for an answer in the **onPusherEventsCallback** and expecting the events "_**idcard-processed" and "selfie-compare-processed".**_

**idcard-processed:** id document validation results are ready

_**selfie-compare-processed:**_ matching results are ready

## Callback params

| submitIdCard Callback | Callback                     |
| --------------------- | ---------------------------- |
| Boolean status        | Status of request            |
| StepType previous     | Previous step                |
| StepType next         | Next step                    |
| JsonObject json       | JsonObject data from request |
| Errors e              | Errors object                |

## Implementation example

```java
public class ExampleActivity extends Activity implements OnProcessCallback {
    private ArrayList<String> files;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_example);

        LivnessCustomisarion customisation = new LivenessCustomisation();
        customization.setPublicKey("PUBLIC KEY");
        customization.setLivenessToken("LIVENESS TOKEN");
        
        Fragment surface = BiometridOn.getInstance().generateLivenessWithOcrSurface("TOKEN", StepType.OcrSelfie, DocType.IdCard, customisation, files, this);
        
        //example
        getFragmentManager()
                        .beginTransaction()
                        .replace(R.id.surface_view, fragment, "liveness_fragment")
                        .addToBackStack(null)
                        .commit();
    }

    @Override
    public void onDataSubmissionCallback(Boolean status, StepType previous, StepType next, JsonObject json, Errors e) {
        
    } 

     @Override
    public void onPusherEventsCallback(@NonNull String s, @NonNull String event, @NonNull JSONObject jsonObject, @Nullable Errors errors) {

    }

...
}
```
