Android 内部蓝牙打印机错误-在PrinterInterface.open上失败

Android 内部蓝牙打印机错误-在PrinterInterface.open上失败,android,bluetooth,Android,Bluetooth,我为wizarhand设备开发了一个应用程序,该设备具有内置蓝牙设备。我可以连接所有外部蓝牙设备,但连接内部设备时会出现以下错误: 在PrinterInterface.open上失败 这是我的代码: public BTPrinter(String namePrefix) throws Exception { BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); Set pairedDe

我为wizarhand设备开发了一个应用程序,该设备具有内置蓝牙设备。我可以连接所有外部蓝牙设备,但连接内部设备时会出现以下错误:

在PrinterInterface.open上失败

这是我的代码:

public BTPrinter(String namePrefix) throws Exception {
        BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
        Set pairedDevices = btAdapter.getBondedDevices();
        String address = null;
        Iterator e = pairedDevices.iterator();

        BluetoothDevice device;
        while(e.hasNext()) {
            device = (BluetoothDevice)e.next();
            if(device.getName().equals("WizarPOS_Printer")) {
                address = device.getAddress();
                this.deviceName = device.getName();
                break;
            }
        }

        if(address == null) {
            Log.d("BTPrinter", "Bluetooth Printer Not Found.");
        }

        device = btAdapter.getRemoteDevice(address);

        try {
            if(Build.VERSION.SDK_INT >= 10) {
                try {
                    this.btSocket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
                } catch (Exception var12) {
                    ;
                }
            }

            if(this.btSocket == null) {
                this.btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
            }
        } catch (IOException var13) {
            Log.d("BTPrinter", "Failed to create bluetooth socket.");
        }

        btAdapter.cancelDiscovery();

        try {
            this.btSocket.connect();
        } catch (Exception var11) {
            Log.d("BTPrinter", "Failed to connect to printer.");

            try {
                this.btSocket.close();
            } catch (Exception var10) {
                ;
            }
        }

        if(!this.btSocket.isConnected()) {
            try {
                Thread.sleep(400L);
            } catch (InterruptedException var8) {
                Thread.currentThread().interrupt();
            }

            throw new Exception("Bluetooth connection issue");
        } else {
            try {
                this.outStream = this.btSocket.getOutputStream();
                this.inStream = this.btSocket.getInputStream();
                Log.d("BTPrinter", "Connected to " + this.deviceName + ".");
            } catch (IOException var9) {
                throw new Exception("Bluetooth connection issue");
            }
        }
    }