# MD for: https://www.mercadopago.com.mx/developers/es/docs/smartapps/terminal-features/configure-bluetooth.md \# 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. :::AccordionComponent{title="Bluetooth management in 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. * [java ](#editor%5F2) * [kotlin ](#editor%5F1) kotlin java ``` val bluetoothUiSettings = MPManager.bluetoothUiSettings bluetoothUiSettings.launch(context) ``` Copiar ``` final BluetoothUiSettings bluetoothUiSettings = MPManager.INSTANCE.getBluetoothUiSettings(); bluetoothUiSettings.launch(context); ``` Copiar This component provides various functionalities, such as enabling and disabling Bluetooth, searching for devices, pairing and unpairing, among others. ::: :::::AccordionComponent{title="Status management via SDK"} 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. ::::TabsComponent :::TabComponent{title="Enable and disable Bluetooth"} To enable and disable Bluetooth on the Point terminal, use the \`turnOn\` or \`turnOff\` functions, respectively, as shown in the example below. * [java ](#editor%5F4) * [kotlin ](#editor%5F3) kotlin java ``` 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 } } ``` Copiar ``` final BluetoothIgnitor bluetoothIgnitor = MPManager.INSTANCE.getBluetooth().getIgnitor(); final Function1, Unit> callback = (final MPResponse 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); ``` Copiar ::: :::TabComponent{title="Check current Bluetooth status"} To check the current Bluetooth status on the Point terminal, use the \`getCurrentState\` function, as shown in the example below. * [java ](#editor%5F6) * [kotlin ](#editor%5F5) kotlin java ``` val bluetoothIgnitor = MPManager.bluetooth.ignitor bluetoothIgnitor.getCurrentState { result -> result .doIfSuccess { state -> if (state) { // Bluetooth is on // Perform additional actions if necessary } else { // Bluetooth is off // Perform additional actions if necessary } } .doIfError { error -> // Handle error case if necessary } } ``` Copiar ``` final BluetoothIgnitor bluetoothIgnitor = MPManager.INSTANCE.getBluetooth().getIgnitor(); final Function1, Unit> callback = (final MPResponse response) -> { if (response.getStatus() == ResponseStatus.SUCCESS) { if (!response.getData()) { // Bluetooth is on // Perform additional actions if necessary } else { // Bluetooth is off // Perform additional actions if necessary } } else { // Handle error case if necessary } return Unit.INSTANCE; }; bluetoothIgnitor.getCurrentState(callback); ``` Copiar If the response returns the \`isConnected\` function with value \`true\`, it indicates that Bluetooth is enabled and, if it returns value \`false\`, it indicates that it is disabled. ::: :::: ::::: :::::AccordionComponent{title="Device pairing via SDK"} 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. ::::TabsComponent :::TabComponent{title="Search for devices"} 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. * [java ](#editor%5F8) * [kotlin ](#editor%5F7) kotlin java ``` 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 } } ``` Copiar ``` final BluetoothDiscoverDevices bluetoothDiscoverDevices = MPManager.INSTANCE.getBluetooth().getDiscover(); final Function1, Unit> callback = (final MPResponse 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); ``` Copiar 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\`. | ::: :::TabComponent{title="Pair and unpair a device"} To pair or unpair a device from the Point terminal, use the \`pairDevice\` and \`unPairDevice\` functions, respectively, as shown in the example below. Send the device address (\`address\`), returned when \[searching for a device\](https://www.mercadopago.com.mx/en/docs/smartapps/terminal-features/configure-bluetooth#:\~:text=pairing%20via%20SDK-,With,-the%20Point%20terminal). * [java ](#editor%5F10) * [kotlin ](#editor%5F9) kotlin java ``` val bluetoothPairing = MPManager.bluetooth.paring bluetoothPairing.pairDevice(address) { response -> response.doIfSuccess { result -> // Handle pairing success val bondState = result.first val deviceModel = result.second // ... Perform additional actions if necessary }.doIfError { error -> // Handle error case if necessary } } ``` Copiar ``` final BluetoothDevicesPairing bluetoothPairing = MPManager.INSTANCE.getBluetooth().getParing(); final Function1>, Unit> callback = (final MPResponse> response) -> { if (response.getStatus() == ResponseStatus.SUCCESS) { final BluetoothBondState bondState = response.getData().getFirst(); final BluetoothDeviceModel deviceModel = response.getData().getSecond(); // Perform additional actions if necessary } else { // Handle error case if necessary } return Unit.INSTANCE; }; bluetoothPairing.pairDevice(address, callback); ``` Copiar 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 that was 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\`. | ::: :::: ::::: :::::AccordionComponent{title="Connection management via SDK"} 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. ::::TabsComponent :::TabComponent{title="Get paired devices"} To get the list of devices that are paired to the Point terminal, use the \`getPairedDevices\` function, as shown in the example below. * [java ](#editor%5F12) * [kotlin ](#editor%5F11) kotlin java ``` 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 } } ``` Copiar ``` final BluetoothDiscoverDevices bluetoothDiscoverDevices = MPManager.INSTANCE.getBluetooth().getDiscover(); final Function1>, Unit> callback = (final MPResponse> response) -> { if (response.getStatus() == ResponseStatus.SUCCESS) { final List devices = response.getData(); // Work with the list of paired devices } else { // Handle error case if necessary } return Unit.INSTANCE; }; bluetoothDiscoverDevices.getPairedDevices(callback); ``` Copiar 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\`. | ::: :::TabComponent{title="Get paired printers"} To get the list of printers that are paired to the Point terminal, use the \`getPairedPrinterDevices\` function, as shown in the example below. * [java ](#editor%5F14) * [kotlin ](#editor%5F13) kotlin java ``` val bluetoothDiscoverDevices = MPManager.bluetooth.discover bluetoothDiscoverDevices.getPairedPrinterDevices { result -> result .doIfSuccess { printers -> // Work with the list of paired devices } .doIfError { error -> // Handle error case if necessary } } ``` Copiar ``` final BluetoothDiscoverDevices bluetoothDiscoverDevices = MPManager.INSTANCE.getBluetooth().getDiscover(); final Function1>, Unit> callback = (final MPResponse> response) -> { if (response.getStatus() == ResponseStatus.SUCCESS) { final List printers = response.getData(); // Work with the list of paired devices } else { // Handle error case if necessary } return Unit.INSTANCE; }; bluetoothDiscoverDevices.getPairedPrinterDevices(callback); ``` Copiar The response will bring the following values: | Name | Type | Description | |------|------|-----------| | \`id\` | String | Unique identifier of the Bluetooth printer. | | \`boundState\` | Int | Printer 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 | Printer name provided by the operating system. | | \`address\` | String | MAC address of the Bluetooth printer. | | \`isConnected\` | Boolean | Indicates if Bluetooth is connected. If yes, \`true\` and if no, \`false\`. | > NOTE > > To learn how to use a Bluetooth printer from a Point terminal, access \[Configure printing\](https://www.mercadopago.com.mx/developers/en/docs/smartapps/terminal-features/configure-printings). ::: :::: :::::