Pairing a Zebra printer without a PIN code

// Expert user has replied.
P Pietro Francesco Maggi 3 years 5 months ago
175 1 0

Linked to android issue #26041
Issue 26041 - android - ICS can't pair BT devices without PIN - Android Open Source Project - Issue Tracker - Google …

I'm trying to connect a Zebra printer that is configured without a PIN code and I always get a PIN request in the pairing interface. Entering a random PIN result in a "Couldn't pair with MZ320 because of an incorrect PIN or passphrase".
If I change the printer configuration, enabling authentication and setting a PIN, it works.
Given that the customer is currently using these printers with our WM devices without a PIN in place, would be nice if there's a way to achieve the same on Android.

~Pietro

Please Register or Login to post a reply

1 Replies

P Pietro Francesco Maggi

Two news, one bad and one good.
The good news is that I'm able to print without needing to pair the printer with a PIN code.

The bad news is that it only works on JB devices and not on KK devices (tested on MC40, TC55 JB&KK, TC 70 e Nexus 7 KK).

I'm using the code pasted below. On JB it prints, on KK I see the printer turn on the the blue led for the communication and nothing more.

I only get the following Warning in the logs:

11-06 12:10:05.824    2136-2178/com.pietromaggi.sample.printing W/BluetoothAdapter﹕ getBluetoothService() called with no BluetoothManagerCallback
11-06 12:10:05.834    2136-2178/com.pietromaggi.sample.printing D/BluetoothSocket﹕ connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[59]}

But I don't think that this is what generate the issue:
core/java/android/bluetooth/BluetoothAdapter.java - platform/frameworks/base - Git at Google

Any idea/suggestion?

~Pietro

public void pairPrinter()  {
        final UUID SerialPortServiceClass_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
        final BluetoothAdapter BA = BluetoothAdapter.getDefaultAdapter();
        final String PrinterBsid = "00:22:58:0E:E7:87"; // This is My Printer Bluetooth MAC Address

        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                OutputStream sOut;
                BluetoothSocket socket;
                BA.cancelDiscovery();

                BluetoothDevice BD = BA.getRemoteDevice(PrinterBsid);
                try {
                    socket = BD.createInsecureRfcommSocketToServiceRecord(SerialPortServiceClass_UUID);
                } catch (IOException e) {
                    return;
                }

                if (!socket.isConnected()) {
                    try {
                        socket.connect();
                        sOut = socket.getOutputStream();
//                        sOut.write(("Hello World\n").getBytes());
                        String cpclData = "! 0 200 200 210 1\r\n"
                                + "TEXT 4 0 30 40 This is a CPCL test.\r\n"
                                + "FORM\r\n"
                                + "PRINT\r\n";
                        sOut.write(cpclData.getBytes());
                        sOut.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                try {
                    Thread.sleep(1000);
                    socket.close();
                    BA.cancelDiscovery();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        t.start();
    }

CONTACT
Can’t find what you’re looking for?