> For the complete documentation index, see [llms.txt](https://doc.ozforensics.com/oz-knowledge/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.ozforensics.com/oz-knowledge/oz-knowledge/pt-br/guias/developer-guide/sdk/oz-mobile-sdk/android/connecting-sdk-to-api.md).

# Conectando o SDK à API

Para conectar o SDK ao Oz API, especifique a URL da API, [token de acesso](/oz-knowledge/oz-knowledge/pt-br/guias/developer-guide/api/oz-api/use-cases/authentication.md), e [SSL pins](/oz-knowledge/oz-knowledge/pt-br/guias/developer-guide/sdk/oz-mobile-sdk/android/android-sdk-methods-and-properties.md#sslpin) como mostrado abaixo.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
OzLivenessSDK.setApiConnection(OzConnection.fromServiceToken(host, token, sslPins))
```

{% endtab %}

{% tab title="Java" %}

```java
OzLivenessSDK.INSTANCE.setApiConnection(
        OzConnection.Companion.fromServiceToken(host, token, sslPins), 
        null
);
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Observe:

* No aplicativo host, recomenda-se definir o endereço da API na tela que precede a verificação de Liveness. Definir a URL da API inicia uma chamada de serviço para a API, o que pode causar carga excessiva no servidor quando isso for feito na inicialização ou no startup do aplicativo. Recomendamos chamar o `setApiConnection` método uma vez, por exemplo, na `Application` classe.
* A ordem de inicialização do SDK e da conexão com a API não importa, mas ambos os métodos devem ser concluídos com sucesso antes de invocar o `createStartIntent` método.
  {% endhint %}

Como alternativa, é possível usar o login e a senha fornecidos pelo gerente de conta da Oz Forensics:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
OzLivenessSDK.setApiConnection(
    OzConnection.fromCredentials(host, username, password, sslPins),
    statusListener(
        { token -> /* token */ },
        { ex -> /* error */ }
    )
)
```

{% endtab %}

{% tab title="Java" %}

```java
OzLivenessSDK.INSTANCE.setApiConnection(
        OzConnection.Companion.fromCredentials(host, username, password, sslPins),
        new StatusListener<String>() {
            @Override
            public void onStatusChanged(@Nullable String s) {}
            @Override
            public void onSuccess(String token) { /* token */ }
            @Override
            public void onError(@NonNull OzException e) { /* error */ }
        }
);
```

{% endtab %}
{% endtabs %}

Embora a opção preferida seja a autenticação via token de acesso – por motivos de segurança.

Por padrão, os logs são salvos junto com os dados das análises. Se for necessário manter os logs distintos dos dados de análise, configure a conexão separada para [telemetria](/oz-knowledge/oz-knowledge/pt-br/outros/faq.md#what-is-telemetry-and-why-should-i-use-it) como mostrado abaixo:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
OzLivenessSDK.setEventsConnection(
    OzConnection.fromCredentials(
        "https://echo.cdn.ozforensics.com/",
        "<your_telemetry_user_eg_tm@company.com>",
        "your_telemetry_password"
    )
)
```

{% endtab %}

{% tab title="Java" %}

```java
OzLivenessSDK.setEventsConnection(
        OzConnection.fromCredentials(
                "https://tm.ozforensics.com/",
                "<your_telemetry_user_eg_tm@company.com>",
                "your_telemetry_password"
        )
);
```

{% endtab %}
{% endtabs %}

Remoção da autorização:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
OzLivenessSDK.setApiConnection(null)
```

{% endtab %}

{% tab title="Java" %}

```java
OzLivenessSDK.INSTANCE.setApiConnection(null, null);
```

{% endtab %}
{% endtabs %}

### Outros métodos

Verifique a presença do token de acesso salvo da Oz API:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val isLoggedIn = OzLivenessSDK.isLoggedIn
```

{% endtab %}

{% tab title="Java" %}

```java
boolean isLoggedIn = OzLivenessSDK.INSTANCE.isLoggedIn();
```

{% endtab %}
{% endtabs %}

Encerrar sessão:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
OzLivenessSDK.logout()
```

{% endtab %}

{% tab title="Java" %}

```java
OzLivenessSDK.INSTANCE.logout();
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://doc.ozforensics.com/oz-knowledge/oz-knowledge/pt-br/guias/developer-guide/sdk/oz-mobile-sdk/android/connecting-sdk-to-api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
