Device.setPreferredBluetoothPrinter()

Overview

On an Android device, set the MAC address that will be used as the device's preferred Bluetooth printer across all Velocity sessions. If the preferred printer is not available, a notification will be displayed to the user and the job will fail.

Added in version 2.1.29

Use Case

Set a device with a specific MAC address as the preferred Bluetooth printer.

Format

Device.setPreferredBluetoothPrinter(stringValue);

Parameter Description Type Required
stringValue A MAC address to store as the device's preferred printer. String Required

Example 1

Copy
/* Set the MAC address that will be used as the preferred bluetooth printer.
*/
var mac = "1A:2B:3C:4D:5E:6F"
Device.setPreferredBluetoothPrinter(mac);

Example 2

Copy
/* Consumes barcodes that contains a MAC address separated by colons and sets it as the preferred printer.
*/
const macRegex = /^[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}$/;

WLEvent.on("Scan", function (event) {
    if(event.data.match(macRegex)) {
        // the barcode looks like a MAC address, set it as the default printer
        Device.setPreferredBluetoothPrinter(event.data.toUpperCase());
        View.toast("Printer set to " + event.data, true);
        // consume the scan
        event.data = "";
        Device.beep(1200, 100, 70);
        Device.beep(1500, 70, 70);
    }
});