# Manage Bluetooth Connectivity

The RedCLS SDK manages Bluetooth communication with PIN pad devices using the `RedCLSPinPadManager`. This class handles the low-level connection protocol through an interface-based flow, ensuring your application is informed of connection events in real-time.

## Requirements

Before managing connectivity, ensure:
1.  **Permissions**: your app has `BLUETOOTH` and `BLUETOOTH_ADMIN` permissions (and Location for scanning if handling discovery manually).
2.  **Serial Number**: You must have the serial number of the PIN pad you wish to connect to.
3.  **Terminal Data**: You need the `RedCLSTerminalData` object obtained during login.

---

## Step 1: Implement the PIN pad Interface

To receive connection updates, your class (typically an Activity or another component that can safely provide a valid UI context) must implement `RedCLSPinPadInterface`.

```kotlin
import redcls.itpvpc.interfaces.RedCLSPinPadInterface

class MyPaymentActivity : AppCompatActivity(), RedCLSPinPadInterface {

    override fun conexionPinPadRealizada() {
        Log.i("GetMini", "Connection established. You can now initialize the Pinpad.")
        // Proceed to pinpadManager.inicializarPinpad()
    }

    override fun pinPadNoEncontrado() {
        Log.e("GetMini", "Could not find or connect to the Pinpad.")
    }

    // ... implement other methods like getContext(), seleccionMonedaPagoDCC(), etc.
}
```

---

## Step 2: Configure the Connection

Use `RedCLSConfigurationPinPadData` to specify the connection type and the device identifier. For Bluetooth, the "name" parameter must be the **Serial Number** of the PIN pad.

```kotlin
import redcls.itpvpc.data.RedCLSConfigurationPinPadData

val config = RedCLSConfigurationPinPadData(
    RedCLSConfigurationPinPadData.BLUETOOTH_CONNECTION,
    "12345678" // Pinpad Serial Number
)
```

---

## Step 3: Establish the Connection

Instantiate the `RedCLSPinPadManager` using your interface implementation, configuration, and terminal data, then trigger the connection.

```kotlin
import redcls.itpvpc.managers.RedCLSPinPadManager

val pinpadManager = RedCLSPinPadManager(this, config, merchantTerminalData)
pinpadManager.connectWithPinPad()
```

This call is asynchronous. The SDK will notify you through the `conexionPinPadRealizada()` or `pinPadNoEncontrado()` callbacks.

---

## Step 4: Maintenance and Status Checks

The SDK provides methods to verify the connection state or clean up resources when they are no longer needed.

### Checking Connection State
Use `isPinPadConnected()` for a quick check, though be aware that there might be a slight delay in detecting hardware disconnections.

```kotlin
if (pinpadManager.isPinPadConnected()) {
    // Proceed with operations
}
```

### Closing Connections
To release Bluetooth resources when exiting your payment flow:

```kotlin
pinpadManager.cerrarConexiones()
```

---

## Best Practices

- **Initial Connection**: The first connection after the PIN pad wakes up from sleep mode might take a few seconds. Handle this in your UI with a loading indicator.
- **Serial Number Management**: If you support multiple PIN pads, store their serial numbers in your app settings so the user doesn't have to re-enter them.
- **Context Handling**: The `getContext()` method in your interface **must** return a valid UI context (typically an Activity). Providing a Service context may cause issues with UI-related events (like DCC selection or Signature prompts).

## Next Steps

* [Initialize the SDK](/en/get-mini/android-sdk/guides/initialize-sdk-lifecycle) - Learn how to perform the `inicializarPinpad()` call after connecting.
* [Create a Single-Step Payment](/en/get-mini/android-sdk/guides/process-single-step-payments) - Start processing transactions.
* [Configure Android Permissions](/en/get-mini/android-sdk/first-steps/configure-android-permissions) - Verify your manifest settings.