android蓝牙打印机不打印阿拉伯字符(UTF-8)

时间:2015-06-17 11:58:35

标签: android printing bluetooth outputstream bluetooth-socket

我有一台蓝牙打印机,我通常从我的Android应用程序打印英文字符,但是当我写阿拉伯字符时,它打印错误。 我在写入打印机时尝试对outputstream进行编码但没有结果。 这是我的代码

  Set<BluetoothDevice> pairedDevices = mBluetoothAdapter
                    .getBondedDevices();
            if (pairedDevices.size() > 0) {
                for (BluetoothDevice device : pairedDevices) {


                    if (device.getName().equalsIgnoreCase("BlueTooth Printer")) {
                        mmDevice = device;
                        break;
                    }
                }
            }

这是我打印数据的方式:

        void sendData() throws IOException {
        try {

            // the text typed by the user
            String msg = myTextbox.getText().toString();
            msg += "\n";

            mmOutputStream.write(msg.getBytes(Charset.forName("UTF-8")));

            // tell the user data were sent
            myLabel.setText("Data Sent");

        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

0 个答案:

没有答案