1

我正在开发通过蓝牙与打印机连接并打印一些文本的应用程序。我可以通过蓝牙连接打印机,然后从 BluetoothSocket 获取 outputStream 并写一些文本。但它不会在打印机中打印任何东西......我仔细检查过没有例外。请帮助我在我的代码中做错了什么???`我已经使用佳能 MX430 打印机进行测试.. 这是我的代码

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

1 回答 1

0

我过去曾尝试过,但使用的是热敏打印机。那里的期望是要写入流的数据必须遵循某些协议才能打印。这个问题可能是相似的。

于 2013-07-02T06:26:52.203 回答