CloudPOS SDK
  • CloudPOS SDK
    • EMV Develop Spec
    • Scanning Service Usage
    • API Specification
    • CloudPOS SDK AAR
    • Java API Samples
    • Permissions
    • Error code
    • MDB Communication Protocal
  • POS_Specs
  • FAQ
    • SDK Error Collection
      • Printer
      • PINPAD
      • Contactless Card
      • IC Card
      • MSR Card
    • Hardware/Repair
      • Recover a Tampered Terminal
      • Learning Tampered Events
      • Remotely Reactivate from Tamper
      • TF (Micro SD) Card Suggestion
      • Understand Tamper Reason
    • Printer
      • Verify Terminal Printer Status
      • Print Unsupported Character Sets
      • Use Terminal Bluetooth Printer
      • Print Images
      • Print QR Codes
      • Evaluate HTML Print Performance
      • Evaluate Print Performance
      • Print with TM T88IV
      • Replace HTML Print Font
      • Java API Printer Operations
      • Understanding Image Print Gaps
      • Print with JavaScript
      • Verify Printer Paper Status
    • USB/Serial Port
      • Install Terminal USB Drivers
      • Install UU Cable Driver
      • Reinstall Production Serial Drivers
      • Linux Serial Driver Installation
      • Serial Port Development
      • Add Linux Udev Rules
      • ReOpen Serial after Wake-up
      • Close Serial after Disconnect
      • Connect Accessory Mode
      • Detect UU Cable Connnected
      • Control Fan via Serial Port
      • List Connected USB Devices
      • Accessory Agent Service D22/Q3
    • Firmware
      • Update Firmware
      • Understand Firmware Naming
      • Compare Engineer/User Modes
      • Configure POS Home Settings
      • Configure POS System Settings
      • Prevent Accidental App Uninstallation
      • Troubleshoot "Agent Stopped" Error
      • Resolve Forgotten Lock Password
      • Utilize Q1 Buttons
      • Adapt Q1 4G
      • Customize Boot Logo/Animation
      • Set Wallpaper
      • Activate Startup Special Mode
      • Install Browsers
      • Understand Firmware External Access
      • Get Terminal Firmware Modes
      • Write Customer Serial Numbers
      • Enable Touch Screen Wake-Up
      • Set User System Properties
      • Enable and Disable MTP
      • Update POS WebView
      • Disable File Explorer for TF/Pendrives
      • Manage Screen On/Off
      • Disable notification badges
      • Scheduled Terminal Reboot Setup
    • Settings Menu
      • Perform Factory Data Reset
      • Understand Settings Menus
      • View Terminal Certificate List
      • Understand Merchant Self Test
      • Use Network Self-Test
      • Change System Language
      • Log in as Administrator
      • Change Administrator's Login Password
      • Update Terminal Time
      • Update Terminal Time Zone
      • Update Time Zone from IP
      • Enable Settings Menu Role Control
      • Update Role Passwords API
      • Disable Bluetooth/Wi Fi
      • Enable/Disable Auto Time Zone
      • Enable/Disable Automatic Time
      • Set Display Sleep
      • Grant Accessibility Permission Automatically
      • Disable Security Lock
      • Access Settings Sub Menu
      • Set Language API
    • Battery/Power
      • Understand Special Charging Indicator
      • Preserve Terminal Battery Life
      • Understand Q2 Low-voltage Shutdown
      • Understand Terminal Battery Performance
      • Understand Counter Mode
      • Turn Off Terminal API
    • SIM/Ethenet/WIFI
      • Disable POS Hotspot
      • Activate POS Hotspot
      • Retrieve Terminal IMEI Number
      • Retrieve Terminal MEID Number
      • Understand Modem Bands
      • Troubleshoot Terminal SIM Signal
      • Resolve SIM Network Issues
      • Troubleshoot Network Search Error
      • Check eSIM Status
      • Ethernet Connectivity Usage
      • Set Communication Mode
      • Troubleshoot USSD Issues
      • Set Preferred Network Type API
      • Add APN API
      • Set Static Ethernet API
      • Enable/Disable Mobile Data API
      • Set Network Operators API
      • Activate eSIM
      • Enable/Disable Ethernet
    • Certificate
      • Apply App Certificates
      • Renew App Certificate
      • App Installation Controls
      • Install CA Certificates
      • Clear Terminal Certificates
      • Understand Certificate Visibility
    • Card
      • Contactless Card Distance
      • NFC Buffer Size Understanding
      • Use Contactless CPU Card
      • Use Felica Card
      • Use Mifare Card
      • Understand PSAM Card Exceptions
      • Optimal Tap Positioning Guide
    • FingerPrint
      • Fingerprint Module Usage Guide
      • Fingerprint DPI Specifications
      • Fingerprint Data Formats
    • Other Development
      • New Android Studio Versions
      • Setup ANDROID HOME
      • App Signing Process
      • Install POS Applications
      • Create First Android App
      • Retrieve Terminal Logs
      • Resolve APK Signature Conflict
      • Obtain Unfiltered Full Log
      • Obtain Terminal Current Location
      • Use Terminal Camera
      • Get Test APKs
      • Learn ADB Commands
      • Get Advanced Demos
      • Import Java SDK in C
      • Obtain Signal Strength
      • Get D3 Demos
      • Learn Kiosk Mode
      • Block Status Bar API
      • Display Full-Screen API
      • Display Full Screen Android API
      • Disable Home Key
      • Capture Power Button API
      • Retrieve Terminal Info
      • Save Files Locally
      • Set Default Launcher
      • Get Firmware Version
      • Get Firmware&EMV Version
      • Implement TLSv1.3
      • Auto-Run Post-Install
      • Understand Secure Connections
      • Use AnyDesk
      • Export Database to SD
      • Migrate App to Q2Premium
      • Auto-Run App Post-Boot
      • Integrate Java SDK in Flutter
      • Call AIDL Interface
      • Connect wirelessly
      • Get POS SN
      • UPT development-related
      • Q3 PDA Terminal Barcode Scanner
    • Key Injection
      • Inject Test Keys Remotely
      • Understand DUKPT
      • Understand Master&Session Keys
      • Use TMK KeyLoader POS
      • Understand Remote Key Injection
      • Resolve Serial Timeout
      • Import TMK Error: 74496
    • PINPAD
      • PINPAD Configuration Summary
      • Customize PINPAD GUI
    • TMS/Wizarview
      • TMS Overview
      • TMS User Guide
      • Register Terminal to WizarView
      • Accept TMS File Downloads
      • Handle User Locked Status
      • Apply WizarView Account
      • Batch Import Terminals
      • Unbind App Configuration
      • Remove App via TMS
      • Understand Agent Error Codes
      • Understand TMS IP Ports
      • Understand Update Scenarios
      • Understand App Binding Types
      • Apply RMA Maintenance Account
      • Update Firmware Remotely
      • Push APK to Specific Device
      • Set Agent Working Mode
      • Manage APK Prompt Installation
      • Network Control in Agent
      • Push Apps Using Tags
      • Deploy AID/CAPK via TMS
    • EMV
      • What's Tag91
      • What's CAPK
      • Set Issuer Scripts
      • Resolve Detection Priority Conflict
  • Wizarview Open API
Powered by GitBook
On this page
  • Initial Setup:
  • Service Overview:
  • Service Startup Process:
  • Prerequisites for Use:
  • Getting Started with Development:
  • Code snippet
  • Download Bluetooth demo
  1. FAQ
  2. Printer

Use Terminal Bluetooth Printer

PreviousPrint Unsupported Character SetsNextPrint Images

Last updated 7 months ago

Initial Setup:

Not all terminals come with the Bluetooth printer service pre-installed. Before proceeding, ensure you download and install the bluetooth printer service APK.

  • .

  • .

Service Overview:

The Bluetooth printer service facilitates printing images and text using Bluetooth APIs. This service operates by connecting with Bluetooth printers and sending data for printing. Data is typically formatted as image and text documents.

Service Startup Process:

  1. Turning on Bluetooth: Automatically activates Bluetooth if it's not already on.

  2. Scanning for Devices: Discovers nearby Bluetooth devices.

  3. Pairing: Selects and pairs with a Bluetooth printer.

  4. Connecting: Establishes a connection using the Serial Port Profile (SPP).

  5. Data Transmission: Sends data in the form of ESC commands.

  6. Printing: Executes the print command for the transmitted data.

Prerequisites for Use:

  • Android SDK 24

  • Android Build Tools v27.0.0

  • Android Support Repository

  • ZXing (for barcode processing)

Getting Started with Development:

To build the Bluetooth printer service, you can use Gradle. Execute the gradle build command or use the "Import Project" option in Android Studio to get started.

Code snippet

  • Basic API of Bluetooth

    public void openBluetooth(Activity activity) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        activity.startActivityForResult(enableBtIntent, 1);
    }
    public void closeBluetooth() {
        this.bluetoothAdapter.disable();
    }
    public void searchDevices() {
        this.bluetoothAdapter.startDiscovery();
    }
    private BroadcastReceiver receiver = new BroadcastReceiver() {
        ProgressDialog progressDialog = null;
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (BluetoothDevice.ACTION_FOUND.equals(action)) {
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
                    addBondDevice(device);
                } else {
                    addUnbondDevice(device);
                }
            } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                String msg = "ACTION_ACL_CONNECTED: " + device.getAddress() + "=" + device.getBondState();
                Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
                System.out.println(msg);
            } else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
                progressDialog = ProgressDialog.show(context, "pair...","...", true);
            } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED .equals(action)) {
                bluetoothAdapter.cancelDiscovery();
                if (progressDialog != null)
                    progressDialog.dismiss();
                addUnbondDevicesToListView();
                addBondDevicesToListView();
            } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
                int state = bluetoothAdapter.getState();
                if (state == BluetoothAdapter.STATE_ON) {
                    searchDevices.setEnabled(true);
                    bondDevicesListView.setEnabled(true);
                    unbondDevicesListView.setEnabled(true);
                } else if (state == BluetoothAdapter.STATE_OFF) {
                    searchDevices.setEnabled(false);
                    bondDevicesListView.setEnabled(false);
                    unbondDevicesListView.setEnabled(false);
                } else {
                    System.out.println("Bluetooth.STATE: " + state);
                }
            } else {
                System.out.println("Bluetooth.ACTION: " + action);
            }
        }
    };
  • Connection with SPP

public boolean connect() {
    if (!isConnected) {
        try {
            bluetoothSocket = createBluetoothSocket();
            bluetoothSocket.connect();
            outputStream = bluetoothSocket.getOutputStream();
            isConnected = bluetoothSocket.isConnected();
            if (this.bluetoothAdapter.isDiscovering()) {
                Toast.makeText(this.context, "success to connect",1).show();
                this.bluetoothAdapter.isDiscovering();
            }
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(this.context, "fail to  connect", 1).show();

            return false;
        }
    }
    Toast.makeText(this.context, this.device.getName() + "connected",Toast.LENGTH_SHORT).show();
    return true;
}

private BluetoothSocket createBluetoothSocket()
        throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    switch (TYPE_OF_CREATING_SOCKET) {
    case 0: return device.createRfcommSocketToServiceRecord(uuid);
    case 1: return device.createInsecureRfcommSocketToServiceRecord(uuid);
    default:
        Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
        return (BluetoothSocket) m.invoke(device, 1);
    }
}
  • Send and Print

final byte[][] byteCommands = { { 0x1b, 0x40 }, //printer commands(ESC commands)
        { 0x1b, 0x4d, 0x00 },
        { 0x1b, 0x4d, 0x01 },
        { 0x1d, 0x21, 0x00 },
        { 0x1d, 0x21, 0x11 },
        { 0x1b, 0x45, 0x00 },
        { 0x1b, 0x45, 0x01 },
        { 0x1b, 0x7b, 0x00 },
        { 0x1b, 0x7b, 0x01 },
        { 0x1d, 0x42, 0x00 },
        { 0x1d, 0x42, 0x01 },
        { 0x1b, 0x56, 0x00 },
        { 0x1b, 0x56, 0x01 },
public void selectCommand() {
    new AlertDialog.Builder(context).setTitle("Commands").setItems(items, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (isConnected) {
                        try {
                            outputStream.write(byteCommands[which]);
                        } catch (IOException e) {
                            Toast.makeText(context, "write exception",Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(context, "connection is lost",Toast.LENGTH_SHORT).show();
                    }
                }
            }).create().show();
}
public void write(byte[] buff){
    try {
        outputStream.write(buff);
    } catch (IOException e) {
    }
}

Download Bluetooth demo

Bluetooth printer service APK for Q1, Q2 Android 6/7, Q3
Bluetooth printer service APK for Q2 Android 12
Bluetooth Printer APK
Bluetooth Printer Demo