开发者

android bluetooth printer connection?

i had J2ME application to print data byte to printer. But now, i have to convert that code to android code.

My problem is : i can't send data byte[] to mobile printer from my device Galaxy Tab Froyo via bluetooth?

here my simple code :

UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
BluetoothSocket btSocket btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
btSocket.connect();
OutputStream outStream = btSocket.getOutputStream();
String message = "this is message";
byte[] msgBuffer = message.getBytes();
outStream.write(msgBuffer.length);
outStream.write(msgBuffer);

when i see the LogCat, it show that i through all 开发者_如何转开发that process with no error.

can anyone help me?

thanks in advance,

aql


The first thing that comes to my mind is outStream.close() that you forgot to write. Though I am most probably wrong


You need to tell the printer what you are going to print(text, img, barcode). All bluetooth printer use the sam ehexadecimal codes to handle that. Try:

        byte[] arrayOfByte1 = { 27, 33, 0 }; //This defines the FontType we use 2 in the next line for 0 thats the default Font.
        byte[] printformat = { 0x1B, 0x21,(byte)(0x8|arrayOfByte1[2]) }; 

        btoutputstream = btsocket.getOutputStream();

        btoutputstream.write(printformat);
        btoutputstream.write(printAlign);
        btoutputstream.write(message.getBytes());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜