Reputation: 69
I am creating an Android app that will be printing to a Brother QL-720NW Label printer. I have created a sample project for this.
I have imported the necessary JAR file in the libs folder and set the printer settings as suggested in the sample project from Brother. However I keep getting an error that the label is not correct.
I have already seen following thread ERROR_WRONG_LABEL when trying to print wireless using Android Brother Sdk for label printer about similar problem.
According the Brother manual labelNameIndex should be set to 5 in my case.
Here's my manifest:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
And here's the printing part of my small demo project:
public void Print(){
Printer myPrinter = new Printer();
PrinterInfo myPrinterInfo = new PrinterInfo();
PrinterStatus myPrinterStatus = new PrinterStatus();
try{
// Retrieve printer informations
myPrinterInfo = myPrinter.getPrinterInfo();
// Set printer informations
myPrinterInfo.printerModel = PrinterInfo.Model.QL_720NW;
myPrinterInfo.port=PrinterInfo.Port.NET;
myPrinterInfo.printMode=PrinterInfo.PrintMode.FIT_TO_PAGE;
myPrinterInfo.paperSize = PrinterInfo.PaperSize.CUSTOM;
myPrinterInfo.ipAddress="192.168.0.193";
myPrinterInfo.macAddress="00:00:00:00:00"; //hidden for security reasons
LabelInfo mLabelInfo = new LabelInfo();
mLabelInfo.labelNameIndex = 5;
mLabelInfo.isAutoCut = true;
mLabelInfo.isEndCut = true;
mLabelInfo.isHalfCut = false;
mLabelInfo.isSpecialTape = false;
myPrinter.setPrinterInfo(myPrinterInfo);
myPrinter.setLabelInfo(mLabelInfo);
// Create bitmap
Bitmap bmap = BitmapFactory.decodeResource(getResources(), R.drawable.printtest);
try{
tView.append("Start" + "\n" );
myPrinter.startCommunication();
PrinterStatus printerStatus = myPrinter.printImage(bmap);
myPrinter.endCommunication();
tView.append(printerStatus.errorCode.toString() + "\n");
}catch(Exception e){
tView.setText(e.toString());
}
}catch(Exception e){
tView.setText(e.toString());
//e.printStackTrace();
}
}
Upvotes: 3
Views: 4315
Reputation: 11891
I had the same problem and I fixed with:
printerInfo.printerModel = PrinterInfo.Model.QL_720NW;
printerInfo.port = PrinterInfo.Port.NET;
printerInfo.ipAddress = "...";
printerInfo.paperSize = PrinterInfo.PaperSize.CUSTOM;
printerInfo.paperPosition = PrinterInfo.Align.CENTER;
printerInfo.orientation = PrinterInfo.Orientation.LANDSCAPE;
printerInfo.labelNameIndex = LabelInfo.QL700.W50.ordinal();
printerInfo.isAutoCut = true;
printerInfo.isCutAtEnd = true;
But the line that made the difference was:
printerInfo.labelNameIndex = LabelInfo.QL700.W50.ordinal();
Where "W50" is the paper type. You can find that paper type id in the manual.pdf
NOTE: we must use the ordinal value and not de Enum value.
Upvotes: 4