I’m trying to understand how can I use the Poynt printer. The code runs from a Fragment and actually raises no exception, but it do not print.
Here are the relevant parts of the code:
public class CartFragment extends Fragment {
private IPoyntReceiptPrintingService mReceiptPrintingService;
private ServiceConnection mSecondScreenConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
Log.d("DEBUG", "IPoyntReceiptPrintingService is now connected");
mReceiptPrintingService = IPoyntReceiptPrintingService.Stub.asInterface(service);
}
public void onServiceDisconnected(ComponentName className) {
Log.d("DEBUG", "IPoyntReceiptPrintingService has unexpectedly disconnected");
mReceiptPrintingService = null;
}
};
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// [...]
getContext().bindService(
new Intent(IPoyntReceiptPrintingService.class.getName()),
mSecondScreenConnection,
Context.BIND_AUTO_CREATE
);
// [...]
}
}
When I try to print (inside an AsyncTask), I use this:
try {
mReceiptPrintingService.printReceipt(
UUID.randomUUID().toString(),
PrintedReceiptBuilder.build(response),
new IPoyntReceiptPrintingServiceListener.Stub() {
@Override
public void printQueued() throws RemoteException {
Snackbar.make(view, "PRINT QUEUED", Snackbar.LENGTH_SHORT).show();
}
@Override
public void printFailed() throws RemoteException {
Snackbar.make(view, "PRINT FAILED", Snackbar.LENGTH_SHORT).show();
}
}
);
} catch (Exception e) {
System.out.println(e.getMessage());
}
The PrintedReceiptBuilder
ignores the parameter, by now. I’ve tried to generate some mock output before:
public class PrintedReceiptBuilder {
public static PrintedReceipt build(SaleResponse sale) {
PrintedReceipt receipt = new PrintedReceipt();
// TODO: Header Image
// HEADER
List<String> header = new ArrayList<>();
receipt.setHeader(header);
// BODY
List<String> body = new ArrayList<>();
body.add("1234567890123456789012345678901234567890");
receipt.setBody(body);
// FOOTER
List <String> footer = new ArrayList<>();
receipt.setFooter(footer);
// TODO: Footer Image
return receipt;
}
}
I also tried to instantiate PrintedReceipt
this way: new PrintedReceipt(Parcel.obtain())
, but it deadlocks itself.