通过蓝牙将Zebra TC26 ZPL Android Studio发送至ZD420

通过蓝牙将Zebra TC26 ZPL Android Studio发送至ZD420,android,kotlin,zebra-printers,Android,Kotlin,Zebra Printers,我尝试从Zebra TC26应用程序向ZD420发送命令。 我用android studio创建应用程序,但我有错误,没有发送命令 我使用斑马图书馆 我的代码: val bAdapter: BluetoothAdapter = BluetoothAdapter.getDefaultAdapter() for (device in bAdapter.bondedDevices) {

我尝试从Zebra TC26应用程序向ZD420发送命令。 我用android studio创建应用程序,但我有错误,没有发送命令

我使用斑马图书馆

我的代码:

                   val bAdapter: BluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
                    for (device in bAdapter.bondedDevices) {
                        sendZplOverBluetooth(device.address.toString())
                    }

private fun sendZplOverBluetooth(theBtMacAddress: String) {
        try {
            val thePrinterConn: Connection = BluetoothConnection(theBtMacAddress)
            thePrinterConn.open()
            if (thePrinterConn.isConnected) {
                val zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ"
                thePrinterConn.write(zplData.toByteArray())
                thePrinterConn.close()
            }
        } catch (e: java.lang.Exception) {
            e.printStackTrace()
        }
    }
错误:

W/System.err: com.zebra.sdk.comm.ConnectionException: Could not connect to device: read failed, socket might closed or timeout, read ret: -1
W/System.err:     at com.zebra.sdk.comm.ConnectionA.throwAsConnectionException(Unknown Source:42)