Saving connection details to use for auto connection


Im working on the Link OS SDK (previous generation) and can successfully connect via USB > select printer > print demo ZPL using the demo application.
the printer.Address = "/dev/bus/usb/001/002".

the model im using is the ZD420 with USB interface only.

Given the address, how can I create a Connection object using connection builder?

So that i can simply print the data after the first printer selection.

Steven Si
The ConnectionBuilder class

The ConnectionBuilder class does not support USB connection.

It's recommended to use UsbDiscover to find the USB connected printer, rather than using hardcoded USB connection string.

// Request for USB Host Permission
protected void findUsbPrinter() {
    new Thread(new Runnable() {

        public void run() {

            // Find printer on USB
            UsbDiscoveryHandler handler = new UsbDiscoveryHandler();
            UsbDiscoverer.findPrinters(getApplicationContext(), handler);

            try {
                while (!handler.discoveryComplete) {

                if (handler.printers != null && handler.printers.size() > 0) {
                    discoveredPrinterUsb = handler.printers.get(0);
                    // Check for permission
                    if (!usbManager.hasPermission(discoveredPrinterUsb.device)) {
                        usbManager.requestPermission(discoveredPrinterUsb.device, permissionIntent);
                    } else {
                        hasPermissionToCommunicate = true;

                } else {
                    // No printer found on USB.
            } catch (Exception e) {
                // Do something


// Handles USB device discovery
class UsbDiscoveryHandler implements DiscoveryHandler {
    public List<DiscoveredPrinterUsb> printers;
    public boolean discoveryComplete = false;

    public UsbDiscoveryHandler() {
        printers = new LinkedList<DiscoveredPrinterUsb>();

    public void foundPrinter(final DiscoveredPrinter printer) {
        printers.add((DiscoveredPrinterUsb) printer);

    public void discoveryFinished() {
        discoveryComplete = true;

    public void discoveryError(String message) {
        discoveryComplete = true;

Once the USB connected printer is discovered, then we can get the connection as shown below. You can save discoveredPrinterUsb object for close/open later without discovering again.

Connection conn = discoveredPrinterUsb.getConnection();


Vote up!
Vote down!

Points: 0

You voted ‘up’

Log in to post comments