【发布时间】: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