1
votes

I m working on the application which connect with printer via bluetooth and print some text. I m able to connect with printer by bluetooth and then get the outputStream from BluetoothSocket and write some text. But it does not print anything in printer... I have checked carefully there is no exception. Please help me what i did wrong in my code ???`I have used Canon MX430 printer for testing.. here is my code

String MY_PRINTER_MAC_ADDRESS="00:12:FF:67:89";// Printer Mac Address
private UUID applicationUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
String test="testing123234123"; 

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(mDeviceAddress);
mBluetoothSocket = mBluetoothDevice.createRfcommSocketToServiceRecord(applicationUUID);
Method m = mBluetoothDevice.getClass().getMethod("createRfcommSocket", new Class[] {     int.class });
mBluetoothSocket = (BluetoothSocket) m.invoke(mBluetoothDevice, 1);
mBluetoothAdapter.cancelDiscovery();
mBluetoothSocket.connect();
OutputStream os=MainActivity.mBluetoothSocket.getOutputStream();    
byte[] buffer=test.getBytes();
os.write(buffer);       
os.flush();
os.close();`
1
As per printer spec here, it allows only JPEG/PNG image, try writing some image.. - ashish
@ashish I have tried you solution.. but it did not work for me. Can you suggest me other solution??? - Parveen
I am not sure but maybe printer supports some OBEX protocol (Basic Image profile or Basic printing profile BIP/BPP) , so the UUID may differ,it would be nice to check @Lucifer solution - ashish
@user1685308 instead of sending file to BT Printer as byte format, just open the file and read it's contain and then send as String format, I was doing that thing in my case. - Lucifer
@Lucifer I have did which you suggest. First I read full string from image and then write using PrinterWriter class. But this solution is also not working for me. Please correct me if i do something wrong?? - Parveen

1 Answers

0
votes

I have tried this in the past but using a thermal printer. There the expectation was that the data to be written onto the stream had to follow certain protocol in order to be printed. The issue could be on similar terms.