public void PrintSomething(View view){
new AsyncTask<Void, Void, Order>() {
String order_id = "6EAJX1Y29K076";
Order o = null;
Printer printer = null;
PrinterConnector pc = new PrinterConnector(mContext, mAccount, null);
PrintJobsConnector pjc = new PrintJobsConnector(getBaseContext());
@Overrideprotected Order doInBackground(Void... voids) {
try {
o = mOrderConnector.getOrder(order_id);
printer = pc.getPrinters().get(0);
} catch (Exception e) {
e.printStackTrace();
}
return o;
}
@Overrideprotected void onPostExecute(Order order) {
super.onPostExecute(order);
if(order != null) {
pj = new StaticPaymentPrintJob.Builder().order(order).build();
String printid = pjc.print(printer, pj);
if (pjc.getPrintJobIds(PrintJobsContract.STATE_DONE).contains(printid)){
...
};
}
}
}.execute();
}
Can also use PrintJobsConnector#getState(String printJobId) to check the state of a specific print job (rather than getting all print jobs for a given state and then checking if your id is in that state).
PrintJobConnector#print(Printer printer, PrintJob printJob) will queue a print job and the return the printJobId.
The print jobs are also trimmed, so depending on the frequency the merchant prints at, the print job will eventually be trimmed and calls to getState will return null.
3 People are following this question.