ERROR_WRONG_LABEL when trying to print wireless using Android Brother Sdk for label printer

后端 未结 3 992
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 19:48

I have trying to print using labels from my android app which using wifi commands Brother QL-720NW label printer. Since I performed factory

相关标签:
3条回答
  • 2020-12-06 19:59

    I resolved this by creating a LabelInfo object, since you have a Label Printer. It's not clear at all in the documentation. You need to set the label info after the printer info.

    PrinterInfo info = myPrinter.getPrinterInfo();
    info.paperSize = PrinterInfo.PaperSize.CUSTOM;
    
    LabelInfo mLabelInfo = new LabelInfo();
    mLabelInfo.labelNameIndex = 5;
    mLabelInfo.isAutoCut = true;
    mLabelInfo.isEndCut = true;
    mLabelInfo.isHalfCut = false;
    mLabelInfo.isSpecialTape = false;
    
    myPrinter.setPrinterInfo(info);
    myPrinter.setLabelInfo(mLabelInfo);
    

    The ERROR_WRONG_LABEL means that you have a wrong value in paperSize or labelNameIndex. I have a P750W label printer with a 24'' paper. I found that value 5 is the good one for this size, but I don't know for your printer.

    0 讨论(0)
  • I had the same problem and figured out that you should specify the labelNameIndex field to the PrinterInfo object. I had the QL-810W printer. I tried many values and nothing worked until I set it to:

       printerInfo.labelNameIndex = LabelInfo.QL700.W62RB.ordinal // -> 17
    

    I figured out the correct value by making a for loop with all integers from 0 to 100 and logging the result until the printing succeeded with this value. I know this is not the optimal solution but I can't find any documentation or reference for these codes.

    Here is the code I used to specify the PrinterInfo object:

        val printerInfo = PrinterInfo()
        printerInfo.printerModel = PrinterInfo.Model.QL_810W
        printerInfo.port = PrinterInfo.Port.NET
        printerInfo.orientation = PrinterInfo.Orientation.PORTRAIT
        printerInfo.paperSize = PrinterInfo.PaperSize.CUSTOM
        printerInfo.align = PrinterInfo.Align.CENTER
        printerInfo.valign = PrinterInfo.VAlign.MIDDLE
        printerInfo.printMode = PrinterInfo.PrintMode.ORIGINAL
        printerInfo.numberOfCopies = 1
        printerInfo.labelNameIndex = LabelInfo.QL700.W62RB.ordinal // -> 17
        printerInfo.isAutoCut = true
        printerInfo.isCutAtEnd = false
        return printerInfo
    
    0 讨论(0)
  • 2020-12-06 20:05

    TL;DR I solved by setting the workPath attribute:

    printerInfo.workPath = context.cacheDir.Path
    

    I noticed that the setPrinterInfo was returning false and when trying to print I received the WRONG_LABEL error code. Debugging the code I figured out that it's related to file writing permission that Brother SDK requires. The documentation is confusing and mentions about needing the WRITE_EXTERNAL_STORAGE if workPath isn't set. Even having this permission I could not make it work. I solved by setting the workPath attribute as shown above.

    0 讨论(0)
提交回复
热议问题