Android 蓝牙 使用打印机和条形码阅读器
我想知道是否有人可以帮助我解决我遇到的问题。我正在使用 android 重写一个最初在 J2ME 中开发的应用程序。我唯一遇到的问题是蓝牙。该应用程序从蓝牙条形码读取器读取信息并将数据发送到蓝牙打印机。
在读取或写入任何数据之前,我会扫描所有蓝牙设备,允许用户选择设备并存储设备的 MAC 地址。
让我们从条形码阅读器开始。设备发现找不到它。为什么?甚至诺基亚设备也能够找到我正在使用的阅读器。
Discovery 找到了打印机,但是当我尝试向其打印数据时,出现 IOException,无法启动发现服务。
使用 J2ME,我使用以下方式连接到两个设备:
bconn = (StreamConnection) Connector.open("btspp://" + addr + ":1;authenticate=false;encrypt=false;master=false");
对于 android,我使用以下内容:
String addr;
BluetoothAdapter bconn=null;
BluetoothDevice btd;
BluetoothSocket btSocket;
private UUID[] uuidSet;
.
.
.
uuidSet=new UUID[1];
uuidSet[0]=UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
try{
bconn=BluetoothAdapter.getDefaultAdapter();
btd=bconn.getRemoteDevice(addr);
btSocket=btd.createRfcommSocketToServiceRecord(uuidSet[0]);
btSocket.connect();
}
catch(Exception se){
System.out.println("open read Error: " + se);
Log.d("0", "Read Error " + se);
}
错误发生在 btSocket.connect 行
经过几个小时的战斗后,我决定将打印机和扫描仪设置到带有 bluesoleil usb 蓝牙设备的 PC 。
当我尝试该应用程序(使用超级终端)时,一切正常。
请问有人有什么建议吗?
问候 史蒂夫
I wonder if anyone could please help me with a problem I am having. I am rewriting an app I origionaly developed in J2ME using android. The only thing I am having an issue with is bluetooth. The application reads information from a bluetooth barcode reader and sends data to a bluetooth printer.
Before any data is read or written, I scan for all bluetooth devices, allow the user to select a device and store the devices MAC Address.
Lets start with the barcode reader. Device discovery does not find it. Why? even a Nokia device is able to find the reader I am using.
Discovery finds the printer, but when I try print data to it I get an IOException, unable to start discovery service.
Using J2ME I connected to both devices using:
bconn = (StreamConnection) Connector.open("btspp://" + addr + ":1;authenticate=false;encrypt=false;master=false");
With android I am using the following:
String addr;
BluetoothAdapter bconn=null;
BluetoothDevice btd;
BluetoothSocket btSocket;
private UUID[] uuidSet;
.
.
.
uuidSet=new UUID[1];
uuidSet[0]=UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
try{
bconn=BluetoothAdapter.getDefaultAdapter();
btd=bconn.getRemoteDevice(addr);
btSocket=btd.createRfcommSocketToServiceRecord(uuidSet[0]);
btSocket.connect();
}
catch(Exception se){
System.out.println("open read Error: " + se);
Log.d("0", "Read Error " + se);
}
The error occurs at the btSocket.connect line
After battling for a few hours I decided to set up my printer and scanner to a PC with a bluesoleil usb bluetooth device.
When I tried the app (using hyperterminal) everything works.
Does anyone have any suggestions please.
Regards
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论