Android Bluetooth Using printers and barcode readers
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 bl开发者_运维百科uetooth device.
When I tried the app (using hyperterminal) everything works.
Does anyone have any suggestions please.
Regards Steve
精彩评论