以编程方式连接到蓝牙棒code在Android的扫描仪 [英] Programmatically connecting to a Bluetooth enabled barcode scanner in Android
问题描述
我的工作创造一个Android应用程序,连接到蓝牙吧code扫描仪。我一直在寻找如何做到这一点code的例子,但我找不到任何处理连接的设备。我看到很多连接的对等与Android设备,但是这似乎并没有覆盖到的Android设备。
这是在code我有这么远。它没有在调用一个连接被拒绝连接。
UUID UUID = UUID.fromString(00001101-0000-1000-8000-00805F9B34FB);
插座= mDevice.createRfcommSocketToServiceRecord(UUID);
Socket.connect()的;
06-11 15:29:10.113:W / System.err的(20018):java.io.IOException异常:连接被拒绝
06-11 15:29:10.133:W / System.err的(20018):在android.bluetooth.BluetoothSocket.connectNative(本机方法)
06-11 15:29:10.133:W / System.err的(20018):在android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:212)
该装置是搭配了Android手机,我用这个从电话上。
设置< BluetoothDevice类> pairedDevices = btAdapter.getBondedDevices();
createInsecureRfcommSocketToServiceRecord
是一个很大的提示。
我必须连接到蓝兆WT32-A蓝牙模块的问题。
我的老code是根据被拒绝蓝牙聊天的例子(其中正常工作与BTM 222蓝牙模块),并使用 createRfcommSocketToServiceRecord
,与连接的结果是:
java.io.IOException异常:连接被拒绝
古怪,试图通过 createRfcommSocketToServiceRecord
连接连连,在很短的间隔,也有时工作。
另外需要注意:使用 createInsecureRfcommSocketToServiceRecord
的需要API级别10
I am working to create an Android App that connects to a bluetooth barcode scanner. I've been looking for code examples of how to do this but I can not find any dealing with connecting to a device. I see lots for connecting peer-to-peer with android devices but that doesn't seem to cover android to device.
This is the code I have so far. It fails on the call to connect with a Connection refused.
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
socket = mDevice.createRfcommSocketToServiceRecord(uuid);
socket.connect();
06-11 15:29:10.113: W/System.err(20018): java.io.IOException: Connection refused
06-11 15:29:10.133: W/System.err(20018): at android.bluetooth.BluetoothSocket.connectNative(Native Method)
06-11 15:29:10.133: W/System.err(20018): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:212)
The device is paired with the android phone and I retrieve it from the phone using this.
Set<BluetoothDevice> pairedDevices = btAdapter.getBondedDevices();
createInsecureRfcommSocketToServiceRecord
was a great hint.
I had problems connecting to a Bluegiga WT32-A Bluetooth module.
My old code was based on Bluetooth Chat example (which worked fine with an BTM 222 Bluetooth module) and used createRfcommSocketToServiceRecord
, with the result of the connection being refused:
java.io.IOException: Connection refused
Weirdly, trying to connect by createRfcommSocketToServiceRecord
again and again, in short intervals, did sometimes work.
Another thing to note: The use of createInsecureRfcommSocketToServiceRecord
requires API level 10.
这篇关于以编程方式连接到蓝牙棒code在Android的扫描仪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!