this.printerDev.printerInit( new IPrinterCallback.Stub() {
// @Override
// public void onException(int i, String s) throws RemoteException {
// showMessage(getResources().getString(R.string.print_status)+ i + s);
// }
// @Override
// public void onLength(long l, long l1) throws RemoteException {
//
// }
//
// @Override
// public void onRealLength(double v, double v1) throws RemoteException {
//
// }
//
// @Override
// public void onComplete() throws RemoteException {
// String endTime = getCurTime();
// Log.d(TAG,"endTime"+ endTime);
// showMessage(getResources().getString(R.string.print_end_time)+endTime);
// }
// });
改成这样
if (printerCallbackStub != null) {
this.printerDev.printerInit(printerCallbackStub);
} else {
// 处理空对象的情况
Log.d(TAG,"printerCallbackStub == null");
}
IPrinterCallback.Stub printerCallbackStub = new IPrinterCallback.Stub() {
@Override
public void onException(int i, String s) throws RemoteException {
}
@Override
public void onLength(long l, long l1) throws RemoteException {
}
@Override
public void onRealLength(double v, double v1) throws RemoteException {
}
@Override
public void onComplete() throws RemoteException {
String endTime = getCurTime();
Log.d(TAG,"endTime"+ endTime);
showMessage(getResources().getString(R.string.print_end_time)+endTime);
}
// 实现 IPrinterCallback 接口的方法
};

文章描述了如何在Java代码中通过`IPrinterCallback.Stub`实现打印机初始化,并处理可能的异常情况和打印结束时间的记录。

被折叠的 条评论
为什么被折叠?



