4

I have a bluetooth printer and I print english characters from my android app normally, but when I write Arabic characters its print them incorrectly. I try to encode outputstream when write to the printer but no result. this is my code

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


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

this is how i print data:

        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();
        }
    }
Amalo
  • 772
  • 3
  • 13
  • 32
  • How did you generate Arabic string , I meant using which font ? There are some fonts by default they are UTF-8 , I had same problem in printing regional language. IF you print the output on logs , what is being printed Arabic letters or some encode chars ? – Rahul Patil Jun 17 '15 at 12:27
  • i write the message i print in log and its show normal arabic charactes `06-17 15:29:54.719: D/mss(20871): امل` – Amalo Jun 17 '15 at 12:29
  • so did you think that the problem isn't in the encoding method ? – Amalo Jun 17 '15 at 12:29
  • So there some cases with string decoding and encoding , and also depends on the environment on which application is running. It also depends on how the string was encoded , use BT chat provided by Android application use two phones , send the same chars across second phone , check how it is displayed there – Rahul Patil Jun 17 '15 at 12:48
  • so did you mean that if i connect it to wifi it can print arabic characters ? or bluetooth is not the problem? – Amalo Jun 18 '15 at 06:21
  • it might be issue with printer also the way how it decodes .. I meant to say we need to make sure that the decode across devices is same. – Rahul Patil Jun 18 '15 at 06:32
  • i will create android app that send bluetooth messages from device to another and will inform you with the result:) – Amalo Jun 18 '15 at 06:53
  • Try converting text to a bitmap and print bitmap. – Chetan Gaikwad Feb 02 '20 at 15:23

0 Answers0