2011-04-25 164 views
0

我有J2ME應用程序打印數據字節到打印機。 但現在,我必須將該代碼轉換爲android代碼。android藍牙打印機連接?

我的問題是: 我無法通過藍牙從我的設備Galaxy Tab Froyo發送數據字節[]到移動打印機?

在這裏我簡單的代碼:

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); 

當我看到logcat的,它表明我通過與沒有錯誤的所有過程。

任何人都可以幫助我嗎?

在此先感謝,

AQL

回答

1

這使我想到的第一件事是outStream.close(),你忘了寫。儘管我很可能是錯的

+1

我也想過。打印機可能會等待整個頁面的數據(或換頁)或數據的結束,然後纔開始打印。 – alanjmcf 2011-08-30 09:24:31

+0

您是否嘗試過使用[BufferedWriter](http://docs.oracle.com/javase/1.4.2/docs/api/java/io/BufferedWriter.html)? 像'BufferedWrited writer = new BufferedWriter(outStream,SIZE);'。然後嘗試使用不同的緩衝區SIZE值。 – 2013-02-07 08:03:26

0

您需要告訴打印機打印什麼(文本,圖像,條形碼)。所有的藍牙打印機都使用s16eadeadecimal代碼來處理。嘗試:

 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());