首页 文章

如何配对不需要与android的pin的bluetooh设备

提问于
浏览
0

我的Android应用程序需要连接到蓝牙打印机(Zebra Bt打印机)来打印票据,这台打印机 doesn't require authentication (it's set Authentication:OFF) ,但我无法创建与它的连接,因为应用程序要求通过输入一个引脚进行配对,我尝试过默认值,如0000和1234但其中任何一个都有效 .

这是我用来与打印机 Build 连接的代码:

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();
                        }

                    }
                }

当它执行该行时:

clientSocket.connect();

在哪里出现用于输入引脚以与设备 Build 连接的对话框,但我不知道要输入什么代码或如何避免此对话框 .

  • 我在Android 4.1.2中使用Galaxy Tab 3 - 在Api 14中开发

1 回答

相关问题