Configure Bluetooth
Bluetooth is one of the Point terminal features that can be used by your SmartApp to provide more interactive and versatile experiences.
The Mercado Pago SDK offers a set of tools to simplify this configuration and enhance wireless connectivity, also allowing users to configure Bluetooth directly from the application.
To include the Point terminal bluetooth settings interface directly in your application, use the launch method from the BluetoothUiSettings class, as shown in the example below. Send the application context (context) to start the activity.
val bluetoothUiSettings = MPManager.bluetoothUiSettings
bluetoothUiSettings.launch(context)
final BluetoothUiSettings bluetoothUiSettings = MPManager.INSTANCE.getBluetoothUiSettings();
bluetoothUiSettings.launch(context);
This component provides various functionalities, such as enabling and disabling Bluetooth, searching for devices, pairing and unpairing, among others.
The Mercado Pago SDK allows you to enable, disable and check the current Bluetooth status of the terminal, using the BluetoothIgnitor class from the MPManager object. See below how to perform each of these activities.
To enable and disable Bluetooth on the Point terminal, use the turnOn or turnOff functions, respectively, as shown in the example below.
val bluetoothIgnitor = MPManager.bluetooth.ignitor
bluetoothIgnitor.turnOn { response ->
response
.doIfSuccess { result ->
if (result) {
// Bluetooth was enabled successfully
// Perform additional actions if necessary
} else {
// Unable to enable Bluetooth
}
}.doIfError {
// Handle error case if necessary
}
}
final BluetoothIgnitor bluetoothIgnitor = MPManager.INSTANCE.getBluetooth().getIgnitor();
final Function1<MPResponse<Boolean>, Unit> callback = (final MPResponse<Boolean> response) -> {
if (response.getStatus() == ResponseStatus.SUCCESS) {
if (response.getData()) {
// Bluetooth was enabled successfully
// Perform additional actions if necessary
} else {
// Unable to enable Bluetooth
}
} else {
// Handle error case if necessary
}
return Unit.INSTANCE;
};
bluetoothIgnitor.turnOn(callback);
With the Point terminal Bluetooth enabled, see below how the Mercado Pago SDK can be used to search, pair and unpair devices through the BluetoothDiscoverDevices and BluetoothDevicesPairing classes from the MPManager object.
To locate a device to be connected via Bluetooth on the Point terminal, use the startDiscovery function from the BluetoothDiscoverDevices class, as shown in the example below.
val bluetoothDiscover = MPManager.bluetooth.discover
bluetoothDiscover.startDiscovery { response ->
response
.doIfSuccess { discoveryState ->
when (discoveryState.type) {
BluetoothDiscoveryState.Type.STARTED -> {
// Handle discovery start
}
BluetoothDiscoveryState.Type.DEVICE_FOUND -> discoveryState.device?.let { device ->
// Handle discovery of a new device
}
BluetoothDiscoveryState.Type.DEVICE_CHANGE -> discoveryState.device?.let { device ->
// Handle changes in a discovered device
}
BluetoothDiscoveryState.Type.ENDED -> {
// Handle discovery end
}
}
}
.doIfError { error ->
// Handle error case if necessary
}
}
final BluetoothDiscoverDevices bluetoothDiscoverDevices = MPManager.INSTANCE.getBluetooth().getDiscover();
final Function1<MPResponse<BluetoothDiscoveryState>, Unit> callback = (final MPResponse<BluetoothDiscoveryState> response) -> {
if (response.getStatus() == ResponseStatus.SUCCESS) {
switch (response.getData().getType()) {
case STARTED:
// Handle discovery start
break;
case DEVICE_FOUND:
// Handle discovery of a new device
final BluetoothDeviceModel foundDevice = response.getData().getDevice();
break;
case DEVICE_CHANGE:
// Handle changes in a discovered device
final BluetoothDeviceModel changedDevice = response.getData().getDevice();
break;
case ENDED:
// Handle discovery end
}
} else {
// Handle error case if necessary
}
return Unit.INSTANCE;
};
bluetoothDiscoverDevices.startDiscovery(callback);
The response will bring the following values:
| Name | Type | Description |
id | String | Unique identifier of the Bluetooth device. |
name | String | Device name created by the operating system. |
address | String | MAC address of the Bluetooth device. |
isConnected | Boolean | Indicates if Bluetooth is connected. If yes, true and if no, false. |
See below how to use the Mercado Pago SDK to get which devices and printers are paired with the Point terminal, using the BluetoothDiscoverDevices class from the MPManager object.
To get the list of devices that are paired to the Point terminal, use the getPairedDevices function, as shown in the example below.
val bluetoothDiscoverDevices = MPManager.bluetooth.discover
bluetoothDiscoverDevices.getPairedDevices { result ->
result
.doIfSuccess { devices ->
// Work with the list of paired devices
}
.doIfError { error ->
// Handle error case if necessary
}
}
final BluetoothDiscoverDevices bluetoothDiscoverDevices = MPManager.INSTANCE.getBluetooth().getDiscover();
final Function1<MPResponse<List<BluetoothDeviceModel>>, Unit> callback = (final MPResponse<List<BluetoothDeviceModel>> response) -> {
if (response.getStatus() == ResponseStatus.SUCCESS) {
final List<BluetoothDeviceModel> devices = response.getData();
// Work with the list of paired devices
} else {
// Handle error case if necessary
}
return Unit.INSTANCE;
};
bluetoothDiscoverDevices.getPairedDevices(callback);
The response will bring the following values:
| Name | Type | Description |
id | String | Unique identifier of the Bluetooth device. |
boundState | Int | Device pairing status. Can have different values representing distinct states, such as: - none: device not paired. - bonding: device in pairing process. - bonded: device paired. |
name | String | Device name provided by the operating system. |
address | String | MAC address of the Bluetooth device. |
isConnected | Boolean | Indicates if Bluetooth is connected. If yes, true and if no, false. |