Термальный принтер, подключенный к андроид устройству ставит пробелы после каждой буквы кирилицей

Я делаю приложение на андроид, которое распечатывает чеки. Используется мобильный принтер pos80(x80) компании xprinter xenye. Формат соединения - блютуз. При выводе символов кирилицей после каждого символа на чеке печатается пробел. Исходный код:

import android.app.AlertDialog
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothSocket
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.view.MotionEvent
import android.view.View
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
import java.io.IOException
import java.io.OutputStream
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets.UTF_8
import java.util.*
import kotlin.collections.ArrayList
import kotlin.text.Charsets.UTF_8


class MainActivity : AppCompatActivity() {
    private lateinit var outputStream:OutputStream
    private lateinit var mBluetoothAdapter:BluetoothAdapter
    private lateinit var mBluetoothDevice:BluetoothDevice
    private lateinit var mBluetoothSocket:BluetoothSocket
    private val SPP_UUID: UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")
    private lateinit var pairedDevices: ArrayList<String>
    private var mArrayAdapter: ArrayAdapter<String>? = null
    var pairedDevicesList: MutableSet<BluetoothDevice>? = null
    var isConnected = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        //инициализация листа с названием устроств
        pairedDevices = ArrayList()
        pairedDevices.add("choose your device from list of paired devices")

        //адаптер для отображения листа устройст
        mArrayAdapter = ArrayAdapter(
            this,
            android.R.layout.simple_spinner_dropdown_item,
            pairedDevices
        )
        //прикручиваем адаптер к спиннеру
        device_spinner.adapter = mArrayAdapter
        //обработка нажатия на спиннер
        device_spinner.setOnTouchListener(object : View.OnTouchListener {
            override fun onTouch(v: View?, event: MotionEvent?): Boolean {
                when (event?.action) {
                    MotionEvent.ACTION_DOWN -> useBluetoothDevice()
                }
                return v?.onTouchEvent(event) ?: true
            }
        })

        print_message.setOnClickListener {
            printCheck()
        }
    }

    private fun printCheck(){
        try {
            if (message_to_print.text.toString().isEmpty()) {
                Toast.makeText(this,"message is empty",Toast.LENGTH_SHORT).show()
            }
            outputStream = mBluetoothSocket.outputStream
            outputStream.write((message_to_print.text.toString()+ "\n").toByteArray(charset("GBK")))
            outputStream.flush()

        } catch (e: IOException) {
            // TODO Auto-generated catch block
            e.printStackTrace()
            Toast.makeText(this,"ioexception",Toast.LENGTH_SHORT).show()
        }
    }

    private fun useBluetoothDevice() {

        //создание диалога на включение блютуз
        var dialog = AlertDialog.Builder(this)
        dialog.setTitle("Bluetooth is not enabled")
        dialog.setMessage("Please turn on bluetooth to use printer")

        //перенаправит в настройки
        dialog.setNegativeButton("Cancel") { dialog, which ->
            Toast.makeText(
                applicationContext,
                "check will not be printed", Toast.LENGTH_SHORT
            ).show()
        }
        dialog.setNeutralButton("Turn on bluetooth") { dialog, which ->
            startActivity(Intent(Settings.ACTION_SETTINGS));
        }

        //получение доступа к блютуз модулю
        val mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
        //если у андроид устройства нет блютуза
        if (mBluetoothAdapter == null) {
            Toast.makeText(
                applicationContext,
                "device does not have bluetooth", Toast.LENGTH_SHORT
            ).show()
        }
        //открываем диалог о включении блютуза если он отключен, тобиш отображаем диалог
        else if (!mBluetoothAdapter.isEnabled) {
            dialog.show()
        }
        //если блютуз уже включен
        else {

            //получение имени блютуз устройства для отображения в спиннере
            var getName = mBluetoothAdapter.name


            //получение списка спаренных устройств
            pairedDevicesList = mBluetoothAdapter.bondedDevices



            //блютуз включен, но спаренных устройств нет
            if (pairedDevicesList!!.size == 0) {
                dialog.setMessage("Блютуз включен, но устройство не спарено с блютуз принтером чеков.")
                dialog.show()
            }
            else{
                for (device in pairedDevicesList!!) {
                    // Add the name and address to an array adapter to show in a ListView
                    getName = device.name + "#" + device.address
                    pairedDevices.add(getName)
                }
                var temString: String = device_spinner.selectedItem as String;
                if(!isConnected){
                    temString = temString.substring(temString.length - 17);
                    try {
                        mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(temString);
                        mBluetoothSocket = mBluetoothDevice.createRfcommSocketToServiceRecord(SPP_UUID);
                        mBluetoothSocket.connect();
                        isConnected = true
                        Toast.makeText(this,isConnected.toString(),Toast.LENGTH_SHORT).show()
                    } catch (e: Exception) {
                        // TODO: handle exception
                        Toast.makeText(this, "connection failed", Toast.LENGTH_SHORT).show()
                    }
                }else{
                    try {
                        if (message_to_print.text.toString().isEmpty()) {
                            Toast.makeText(this,"message is empty",Toast.LENGTH_SHORT).show()
                        }
                        outputStream = mBluetoothSocket.outputStream
                        var input:ByteArray = (message_to_print.text.toString()+ "\n").toByteArray(charset("GBK"))
                        outputStream.write(input)
                        outputStream.flush()

                    } catch (e: IOException) {
                        // TODO Auto-generated catch block
                        e.printStackTrace()
                        Toast.makeText(this,"ioexception",Toast.LENGTH_SHORT).show()
                    }
                }
            }


        }
    }

}

Ответы (0 шт):