0

Android アプリがあり、Bluetooth プリンターを使用してテキストを印刷しようとしています。問題は、非ラテン文字を正しく印刷できないことです。私はこのコードを持っています:

 public void printTaggedText() throws IOException {
     try {
         byte[] theText = "Întregul text în românește țș".getBytes("utf8 ");

         for (byte bit : theText) {
             System.out.println("Reached: " + Integer.toHexString(bit));
         }

         this.printText(theText);
    } catch (Exception e) {}
}

エンコーディングが正しいかどうかを確認するために for を入れたので、結果の値を調べたところ、問題ないようです (文字列に変換し直したところ、同じテキストが得られました)。

これは printText 関数です。

public void printText(byte[] b) throws IOException {
    synchronized(this) {
        this.write(b);
    }
}

そして、これは書く:

public synchronized void write(int b) throws IOException {
    this.write(new byte[]{(byte)b});
}

public synchronized void write(byte[] b) throws IOException {
    this.write(b, 0, b.length);
}

public synchronized void write(byte[] b, int offset, int length) throws IOException {
    this.mBaseOutputStream.write(b, offset, length);
}

結果は次のようになります。

ここに画像の説明を入力

別のアプリで正しく印刷されるため、プリンターがこれらの文字をサポートしていることはわかっています。

4

1 に答える 1