> For the complete documentation index, see [llms.txt](https://ftcoders.first-tech.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ftcoders.first-tech.com/first-tech-ttp-sdk-pt/utilitarios/bloqueio-de-captura-de-tela-android-e-react-native.md).

# Bloqueio de Captura de Tela (Android e React Native)

Para aumentar a segurança do aplicativo e proteger dados sensíveis durante o manuseio de cartões, é possível impedir que o sistema realize capturas de tela (*screenshots*) ou gravações de vídeo enquanto o app estiver em primeiro plano.

#### 1. Implementação Nativa (Android/Kotlin)

No Android, essa funcionalidade é controlada através das *flags* da janela (`window`). Ao definir a flag `FLAG_SECURE`, o sistema operacional bloqueia capturas e oculta o conteúdo em visualizações de multitarefa.

Para ativar o bloqueio: O método abaixo deve ser chamado ao iniciar o pagamento, garantindo a proteção dos dados desde o começo da transação:<br>

```
private fun setScreenBlock() {
    window.setFlags(
        WindowManager.LayoutParams.FLAG_SECURE,
        WindowManager.LayoutParams.FLAG_SECURE
    )
}
```

Para permitir capturas novamente: Caso o fluxo de pagamento tenha sido finalizado e você deseje permitir que o usuário tire um *print* do recibo ou grave a tela novamente, utilize a seguinte linha de código para limpar a trava de segurança:

```
private fun clearScreenBlock() {
    window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
```

2. Integração com React Native (Native Module)

Para expor essa funcionalidade ao JavaScript, a melhor abordagem é criar um Native Module. Em sua classe que estende `ReactContextBaseJavaModule`, adicione o seguinte método:

```
@ReactMethod
fun setSafeMode(enable: Boolean) {
    currentActivity?.let { activity ->
        activity.runOnUiThread {
            if (enable) {
                activity.window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
            } else {
                activity.window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
            }
        }
    }
}
```

Exemplo de Uso no Componente React Native

No React Native, utilize o hook `useEffect` para gerenciar o estado de bloqueio de acordo com o ciclo de vida da tela. No exemplo abaixo, o modo seguro é ativado ao entrar na tela `Home` .

```
import { useEffect } from 'react';
import { NativeModules } from 'react-native';

export function Home() {
  // ... outras lógicas do componente

  useEffect(() => {
    // Referência ao módulo nativo criado
    const SafeMode = NativeModules.NativeModule;

    // Ativa o bloqueio ao montar a tela
    if (SafeMode && SafeMode.setSafeMode) {
      SafeMode.setSafeMode(true);
    }

    // Função de limpeza (Cleanup): executada ao sair da tela (unmount)
    return () => {
      if (SafeMode && SafeMode.setSafeMode) {
        SafeMode.setSafeMode(false); // Libera a tela para prints novamente
      }
    };
  }, []);

  return (
    // Seu JSX aqui (Container, Input, BottomSheet, etc.)
  );
}
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ftcoders.first-tech.com/first-tech-ttp-sdk-pt/utilitarios/bloqueio-de-captura-de-tela-android-e-react-native.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
