I'm trying to print custom text which is created with the help of order and line item details. I want this custom text to be sent to the printer while the app is not running and the printer should print this custom text. We send a notification to the application which has orderId in the form of string. The notification service runs every time and without a fail notification is received on the app.
What I have tried till now :
METHOD 1:-
TextPrintJob.Builder().text(message).build().print(context, mAccount);
I'm directly sending the message to the printer which should print the message but unfortunately it is not working.
METHOD 2:-
I'm using printerConnector and get the details of the connected printer and wrote asyncTask to print the job. I referred this code on the gitHub example.
new AsyncTask<Void, Void, Printer>() {Even this method doesn't work.
@Overrideprotected Printer doInBackground(Void... params) {
return getPrinter();
}
@Overrideprotected void onPostExecute(Printer printer) {
if (printer == null) {
return;
}
new ReceiptPrintJob.Builder().orderId(orderId).build().print(context, mAccount, printer);
}
}.execute();
NOTE: ReceiptPrintJob.Builder() is deprecated.
Please advice.