我正在使用Epson TM-P80打印机,该打印机使用Epsons Android SDK连接到我的Android 7设备。打印机通过蓝牙连接,我可以从我的应用程序打印。
我在设置setReceiveEventListener()
,setConnectionEventListener()
和setStatusChangeEventListener()
听众时遇到问题,以便我可以持续监控打印机的状态并显示低电量,低纸张的警告卡纸,盖子打开,断开等。
调用connectPrinter()
(使用按钮进行测试)将触发onPtrStatusChange()
侦听器,但仅触发。我希望mPrinter.setInterval(1000);
每秒报告一次,但事实并非如此。永远不会调用onConnection()
。我究竟做错了什么?
公共类MainActivity扩展Activity实现View.OnClickListener,ReceiveListener,ConnectionListener,StatusChangeListener {
private Printer mPrinter = null;
private boolean connectPrinter() {
boolean isBeginTransaction = false;
if (mPrinter == null) {
return false;
}
try {
//mPrinter.connect(mEditTarget.getText().toString(), Printer.PARAM_DEFAULT);
mPrinter.connect("BT:00:01:03:AA:BB:CC", Printer.PARAM_DEFAULT);
// Register the Event Listners
mPrinter.setReceiveEventListener(this);
mPrinter.setConnectionEventListener(this);
mPrinter.setStatusChangeEventListener(this);
// Start monitoring
mPrinter.startMonitor();
mPrinter.setInterval(1000);
}
catch (Exception e) {
ShowMsg.showException(e, "connect", mContext);
return false;
}
@Override
public void onPtrStatusChange(Printer printer, int i) {
// This is only called once
System.out.println("onPtrStatusChange ");
}
@Override
public void onConnection(Object o, int i) {
// This is never outputted
System.out.println("onConnection");
}
}
}
您可以在此处查看SDK文档Epson EPos Android SDK docs