new Thread(new Runnable() {
@Override
public void run() {
PrinterUtil printer = new PrinterUtil(CashierChoosePaymentActivity.this);
printer.print("2018011800000000000345", "2018-01-19 11:27:52", "10.00");
}
}).start();重要的获得 IPrinterprinter
package com.hisun.pos.utils.printer;
import android.graphics.Bitmap;
import com.pax.ipp.service.aidl.Exceptions;
import com.pax.ipp.service.aidl.dal.printer.EFontTypeAscii;
import com.pax.ipp.service.aidl.dal.printer.EFontTypeExtCode;
import com.pax.ipp.service.aidl.dal.printer.Pic;
import com.pax.ippi.dal.interfaces.IPrinter;
public class PrinterTester extends TestLog {
private static PrinterTester printerTester;
private IPrinter printer;
private PrinterTester() {
printer = GetObj.getDal().getPrinter();
}
public static PrinterTester getInstance() {
if (printerTester == null) {
printerTester = new PrinterTester();
}
return printerTester;
}
public void init() {
try {
printer.init();
logTrue("init");
} catch (Exceptions e) {
e.printStackTrace();
logErr("init", e.toString());
}
}
public String getStatus() {
try {
int status = printer.getStatus();
logTrue("getStatus");
return statusCode2Str(status);
} catch (Exceptions e) {
e.printStackTrace();
logErr("getStatus", e.toString());
return "";
}
}
public void fontSet(EFontTypeAscii asciiFontType, EFontTypeExtCode cFontType) {
try {
printer.fontSet(asciiFontType, cFontType);
logTrue("fontSet");
} catch (Exceptions e) {
e.printStackTrace();
logErr("fontSet", e.toString());
}
}
public void spaceSet(byte wordSpace, byte lineSpace) {
try {
printer.spaceSet(wordSpace, lineSpace);
logTrue("spaceSet");
} catch (Exceptions e) {
e.printStackTrace();
logErr("spaceSet", e.toString());
}
}
public void printStr(String str, String charset) {
try {
printer.printStr(str, charset);
logTrue("printStr");
} catch (Exceptions e) {
e.printStackTrace();
logErr("printStr", e.toString());
}
}
public void step(int b) {
try {
printer.step(b);
logTrue("setStep");
} catch (Exceptions e) {
e.printStackTrace();
logErr("setStep", e.toString());
}
}
public void printBitmap(Bitmap bitmap) {
try {
Pic pic = new Pic(bitmap);
printer.printBitmap(pic);
logTrue("printBitmap");
} catch (Exceptions e) {
e.printStackTrace();
logErr("printBitmap", e.toString());
}
}
public String start() {
try {
int res = printer.start();
logTrue("start");
return statusCode2Str(res);
} catch (Exceptions e) {
e.printStackTrace();
logErr("start", e.toString());
return "";
}
}
public void leftIndents(short indent) {
try {
printer.leftIndent(indent);
logTrue("leftIndent");
} catch (Exceptions e) {
e.printStackTrace();
logErr("leftIndent", e.toString());
}
}
public int getDotLine() {
try {
int dotLine = printer.getDotLine();
logTrue("getDotLine");
return dotLine;
} catch (Exceptions e) {
e.printStackTrace();
logErr("getDotLine", e.toString());
return -2;
}
}
public void setGray(int level) {
try {
printer.setGray(level);
logTrue("setGray");
} catch (Exceptions e) {
e.printStackTrace();
logErr("setGray", e.toString());
}
}
public void setDoubleWidth(boolean isAscDouble, boolean isLocalDouble) {
try {
printer.doubleWidth(isAscDouble, isLocalDouble);
logTrue("doubleWidth");
} catch (Exceptions e) {
e.printStackTrace();
logErr("doubleWidth", e.toString());
}
}
public void setDoubleHeight(boolean isAscDouble, boolean isLocalDouble) {
try {
printer.doubleHeight(isAscDouble, isLocalDouble);
logTrue("doubleHeight");
} catch (Exceptions e) {
e.printStackTrace();
logErr("doubleHeight", e.toString());
}
}
public void setInvert(boolean isInvert) {
try {
printer.invert(isInvert);
logTrue("setInvert");
} catch (Exceptions e) {
e.printStackTrace();
logErr("setInvert", e.toString());
}
}
public String statusCode2Str(int status) {
String res = "";
switch (status) {
case 0:
res = "Success ";
break;
case 1:
res = "Printer is busy ";
break;
case 2:
res = "Out of paper ";
break;
case 3:
res = "The format of print data packet error ";
break;
case 4:
res = "Printer malfunctions ";
break;
case 8:
res = "Printer over heats ";
break;
case 9:
res = "Printer voltage is too low";
break;
case 240:
res = "Printing is unfinished ";
break;
case 252:
res = " The printer has not installed font library ";
break;
case 254:
res = "Data package is too long ";
break;
default:
break;
}
return res;
}
}
首先应该获取IDal dal对象,再借助getPrinter()方法获得printer
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/shouji/article-121093-2.html
请问还能经济发展吗
有些人天天骂马云淘宝卖假货