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:
- Permissions: your app has
BLUETOOTHandBLUETOOTH_ADMINpermissions (and Location for scanning if handling discovery manually). - Serial Number: You must have the serial number of the PIN pad you wish to connect to.
- Terminal Data: You need the
RedCLSTerminalDataobject 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.
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.
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.
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.
if (pinpadManager.isPinPadConnected()) {
// Proceed with operations
}Closing Connections
To release Bluetooth resources when exiting your payment flow:
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 - Learn how to perform the
inicializarPinpad()call after connecting. - Create a Single-Step Payment - Start processing transactions.
- Configure Android Permissions - Verify your manifest settings.