【问题标题】:How to pair bluetooh device that doesn't require pin with android如何将不需要pin的蓝牙设备与android配对
【发布时间】:2013-12-08 10:24:33
【问题描述】:

我的安卓应用需要连接蓝牙打印机(Zebra Bt 打印机)来打印票证,这台打印机不需要身份验证(它设置为 Authentication:OFF),但我无法与它建立连接,因为该应用程序要求通过输入 pin 进行配对,我尝试了 0000 和 1234 等默认值,但它们中的任何一个都有效。

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

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

是用于输入与设备建立连接的 pin 的对话框出现在哪里,但我不知道要输入什么代码或如何避免此对话框。

-我正在使用带有 Android 4.1.2 的 Galaxy Tab 3 -在 Api 14 中开发

【问题讨论】:

  • 你试过用 createInsecureRfcommSocket() 代替 createRfcommSocketToServiceRecord() 吗?

标签: android printing bluetooth


【解决方案1】:

Zebra 提供 Android SDK 供其打印机使用。具体来说,有一个 BluetoothConnectionInsecure 类允许您连接到打印机而无需提供配对信息:http://www.zebra.com/us/en/products-services/software/link-os/link-os-sdk.html。 JavaDoc 中包含完整示例。

如果您无法使用 SDK,那么 BitBank 建议使用 CreateInsecureRfCommSocket() 是一个不错的选择。以下是一些关于其用法的文章:

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

How to create Insecure RFCOMM Socket in Android?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 2013-05-31
    • 2021-04-26
    • 2015-06-25
    • 1970-01-01
    相关资源
    最近更新 更多