I've been trying to print with Brother Print SDK 3.5.1 on Android 8.1.0. I keep getting ERROR_WRONG_LABEL
.
This is the code I use
void printPdf() {
// Specify printer
final Printer printer = new Printer();
PrinterInfo settings = printer.getPrinterInfo();
settings.printerModel = PrinterInfo.Model.QL_810W;
settings.port = PrinterInfo.Port.NET;
settings.ipAddress = "192.168.1.73";
settings.workPath = "storage/emulated/0/Download/";
// Print Settings
settings.labelNameIndex = LabelInfo.QL700.W62RB.ordinal();
settings.printMode = PrinterInfo.PrintMode.FIT_TO_PAGE;
settings.orientation = PrinterInfo.Orientation.PORTRAIT;
settings.isAutoCut = true;
printer.setPrinterInfo(settings);
// Connect, then print
new Thread(new Runnable() {
@Override
public void run() {
if (printer.startCommunication()) {
PrinterStatus result = printer.printPdfFile("/storage/emulated/0/Download/hello world red.pdf", 1);
if (result.errorCode != PrinterInfo.ErrorCode.ERROR_NONE) {
Log.d("TAG", "ERROR - " + result.errorCode);
}
printer.endCommunication();
}
}
}).start();
}
My printer model is QL-810W and I use the black and red W62 roll.
- I've tried the Sample Application, where setting
W62RB
inlabelNameIndex
prints fine. - Changing the roll for different one with different width didn't help.
- I've also tried iterating over numbers 0 to 50 and using them as
labelNameIndex
. - Based on this thread, I thought that the issue may be in specifying the
workPath
attribute. SettingworkPath
togetContext().getCacheDir().getPath()
results inERROR_OUT_OF_MEMORY
instead ofERROR_WRONG_LABEL
. Not specifyingworkPath
and adding<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
toAndroidManifest.xml
results inERROR_WRONG_LABEL
EDIT
I've modified the Brother Sample app and uploaded it to GitHub. The app now launches Activity_PrintPdf.java
by default where I inserted my printing code with hardcoded values at the beginning of onCreate
method - this works fine and prints the PDF file as expected.
Then I created a new Empty Activity project in Android Studio, copy pasted the library, added the imports to build.gradle
and copy pasted the permissions into AndroidManifest.xml
. Then I copy pasted the printing code at the beginning of onCreate
method in MainActivity.java
. Running the app results in ERROR_WRONG_LABEL
.
This is the modified working example app and this is the one that results in the error. I want to use the code as native module that I call from my React Native app, so it's important that I manage to set up the printing code from scratch rather than modifying the existing example app.
EDIT 2
I've inspected the library with a debugger: when executing printer.setPrinterInfo(mPrinterInfo)
the library internally calls private boolean createWorkPath(String dirPath)
of Printer
object. On return from this method, the debugger shows Source code doesn't match the bytecode
and seems to forget the created directory. This also internally sets mResult.errorCode = ErrorCode.ERROR_WORKPATH_NOT_SET
. However, instead of rising any error here the code just silently proceeds, which later results in ERROR_WRONG_LABEL
when trying to print. Running the same code snipper in the modified Sample app works fine.
I'd be grateful if you could help or suggest what to try next.
Thank you!