【问题标题】:android bluetooth printer connection?安卓蓝牙打印机连接?
【发布时间】:2011-04-25 07:29:17
【问题描述】:

我有 J2ME 应用程序将数据字节打印到打印机。 但是现在,我必须将该代码转换为 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

【问题讨论】:

    标签: android bluetooth


    【解决方案1】:

    我首先想到的是你忘记写的outStream.close()。虽然我很可能是错的

    【讨论】:

    • 是的,我也想知道。打印机可能会等待一整页的数据(或换页)或数据结束后才开始打印。
    • 你试过使用BufferedWriter吗?喜欢BufferedWrited writer = new BufferedWriter(outStream, SIZE);。然后尝试不同的缓冲区大小值。
    【解决方案2】:

    您需要告诉打印机您要打印什么(文本、img、条形码)。所有蓝牙打印机都使用相同的十六进制代码来处理。试试:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      • 2014-08-31
      • 2011-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多