0

My android app requires connecting to a bluetooth printer (Zebra Bt Printer) to print tickets, this printer doesn't require authentication (it's set Authentication:OFF), but i cant create a connection with it because the app asks to make pairing by entering a pin, i've tried default values like 0000 and 1234 but any of them works.

This is the code i use to create a connection with the printer:

Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices();

            for (BluetoothDevice device : devices) {
                if (device.getAddress().equals(PRINTER_DEVICE_MAC_ADDRESS)) {

                    bluetoothDevice = bluetoothAdapter.getRemoteDevice(PRINTER_DEVICE_MAC_ADDRESS);
                    if (bluetoothDevice != null) {
                        try {

                            clientSocket = bluetoothDevice.createRfcommSocketToServiceRecord(uuid);
                            clientSocket.connect();

                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                    }
                }

When it executes the line :

clientSocket.connect();

is where appears the dialog for entering the pin for making the connection with the device, but i dont know what code to enter or how to avoid this dialog.

-I'm using Galaxy Tab 3 with Android 4.1.2 -Developing in Api 14

gustav12
  • 327
  • 3
  • 20
  • Have you tried using createInsecureRfcommSocket() instead of createRfcommSocketToServiceRecord() ? – BitBank Dec 08 '13 at 20:05

1 Answers1

2

Zebra offers Android SDKs for use with their printers. Specifically, There's a BluetoothConnectionInsecure class that allows you to connect to your printers without having to provide pairing information: http://www.zebra.com/us/en/products-services/software/link-os/link-os-sdk.html. Full samples are included in the JavaDoc.

If you cannot use the SDK, then BitBank's suggestion of using CreateInsecureRfCommSocket() is a good choice to make. Here are some articles concerning its usage:

http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#createInsecureRfcommSocketToServiceRecord(java.util.UUID)

How to create Insecure RFCOMM Socket in Android?

Community
  • 1
  • 1
jason.zissman
  • 2,750
  • 2
  • 19
  • 24