Can't get it to print vis USB using Brother Barcode SDK for Flutter - Android

52 Views Asked by At

I'm tring to connect brother printer ql-800 via usb on android, After app runs there is no print. except i see 'cannot open usb' message in the debug section. What have i done so far,

    private void printData(String message) {
        try{
Printer printer = new Printer();
        PrinterInfo settings = printer.getPrinterInfo();
        settings.printerModel = Model.QL_800;
        settings.port = PrinterInfo.Port.USB;
        settings.workPath = this.getFilesDir().getAbsolutePath() + "/";
        if (true) {
            settings.labelNameIndex = LabelInfo.QL1100.W103H164.ordinal();
            settings.printMode = PrinterInfo.PrintMode.FIT_TO_PAGE;
            settings.isAutoCut = true;
        }
        printer.setPrinterInfo(settings);
        Bitmap bitmap = stringToBitmap(message);
        new Thread(new Runnable() {
            @Override
            public void run() {
                if (printer.startCommunication()) {
                      runOnUiThread(new Runnable() {
                            public void run() {
                                Toast.makeText(getApplicationContext(),"start comm", Toast.LENGTH_SHORT).show();
                            }
                        });
                    PrinterStatus result = printer.printImage(bitmap);
                    if (result.errorCode != PrinterInfo.ErrorCode.ERROR_NONE) {
                          runOnUiThread(new Runnable() {
                            public void run() {
                                Toast.makeText(getApplicationContext(),"fail comm"+result.errorCode, Toast.LENGTH_SHORT).show();
                            }
                        });
                        //Log.d("TAG", "ERROR - " + result.errorCode);
                    }
                    printer.endCommunication();
                }
            }
        }).start();
        }
        catch(Exception e){
            runOnUiThread(new Runnable() {
                            public void run() {
                                Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_SHORT).show();
                            }
                        });
        }
    }

I want to take simple text print using my android app. Printer is connected to my phone with USB port.

0

There are 0 best solutions below