问题描述
我正在创建一个 Android 应用程序,它将打印到 Brother QL-720NW 标签打印机.我为此创建了一个示例项目.
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.
我已经在 libs 文件夹中导入了必要的 JAR 文件,并按照 Brother 示例项目中的建议设置了打印机设置.但是我不断收到标签不正确的错误.
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.
我已经看到以下线程 尝试使用 Android Brother Sdk 进行标签打印机无线打印时出现 ERROR_WRONG_LABEL关于类似的问题.
I have already seen following thread ERROR_WRONG_LABEL when trying to print wireless using Android Brother Sdk for label printer about similar problem.
根据 Brother 手册,labelNameIndex 在我的情况下应设置为 5.
According the Brother manual labelNameIndex should be set to 5 in my case.
这是我的清单:
<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();
}
}
推荐答案
我遇到了同样的问题,我已解决:
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();
其中W50"是纸张类型.您可以在 手册.pdf
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.
这篇关于通过 WIFI 使用 Brother SDK 进行 Android 打印 (ERROR_WRONG_LABEL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!