How to use the printer?

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.

1 Like

Do you see any exceptions in logcat?

Hi Dennis!
No, no exception.

When I use implicit intent, it logs this warning, but it’s all:

W/ContextImpl: Implicit intents with startService are not safe: Intent { act=co.poynt.os.services.v1.IPoyntReceiptPrintingService } android.content.ContextWrapper.bindService:517 br.com.pdvend.poynt_app.activities.PrintInvoiceActivity.bindServices:63 br.com.pdvend.poynt_app.activities.PrintInvoiceActivity.onCreate:52

Try This

You need to have a list of PrintedReceiptLine that has to be passed to the receipt.setBody() object.
You are passing a list of strings.

Hi @gabriel

What is the ‘co.poynt.api:android-api-model’ and ‘co.poynt.android.sdk:poynt-sdk’ version that you’re using?

My above example is working for
‘co.poynt.api:android-api-model:1.2.32@jar’
‘co.poynt.android.sdk:poynt-sdk:1.2.8@aar’

@dennis Please correct me if I’m wrong.

Most of the developer units are on build 53. You can see that in Settings > About > PoyntOS version.
These dependencies are correct:
‘co.poynt.api:android-api-model:1.2.32@jar’
‘co.poynt.android.sdk:poynt-sdk:1.2.8@aar’

1 Like

@isdcf, @dennis, Thank you for answering!

As said above, I was using an outdated version of co.poynt.api:android-api-model and co.poynt.android.sdk:poynt-sdk. Even updating it, printing was not working.

My co-workers tried to physically check the printer. The paper was stuck inside it (we’re using the paper which come with Poynt). Since we discovered it and corrected first time, we noticed that it’s an intermittent problem. Sometimes it prints, sometimes don’t, sometimes we reboot Poynt and it works again.

1 Like