请分享您的代码
你尝试过这样的事情吗?
printer = new Print(getApplicationContext());
try {
// Open
printer.openPrinter(
connectionType,
openDeviceName,
Print.FALSE,
Print.PARAM_DEFAULT,
Print.PARAM_DEFAULT);
}
catch (EposException e) {
result.setEposException(e);
return;
}
try {
// Print data if printer is printable
printer.getStatus(printerStatus, batteryStatus);
result.setPrinterStatus(printerStatus[0]);
result.setBatteryStatus(batteryStatus[0]);
if (isPrintable(result)) {
printerStatus[0] = 0;
batteryStatus[0] = 0;
printer.beginTransaction();
isBeginTransaction = true;
printer.sendData(builder, sendTimeout, printerStatus, batteryStatus);
result.setPrinterStatus(printerStatus[0]);
result.setBatteryStatus(batteryStatus[0]);
}
}
catch (EposException e) {
result.setEposException(e);
}
finally {
if (isBeginTransaction) {
try {
printer.endTransaction();
}
catch (EposException e) {
// Do nothing
}
}
}
try {
printer.closePrinter();
}