### Example: Using SettingsSetter to Set and Get Printer Settings (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/settingssetter This Java code snippet demonstrates how to use the SettingsSetter class to send a map of settings to a printer and retrieve the results. It shows how to set a specific setting like 'comm.baud' and retrieve a setting like 'device.friendly_name'. The code handles potential ConnectionException and SettingsException. ```java package test.zebra.sdk.printer.examples; import java.util.LinkedHashMap; import java.util.Map; import com.zebra.sdk.comm.ConnectionException; import com.zebra.sdk.printer.SettingsSetter; import com.zebra.sdk.settings.SettingsException; public class SettingsSetterExample { public static void main(String[] args) { String ipAddress = "192.168.1.100"; Map settingsToSendToThePrinter = new LinkedHashMap(); // Pass in a null as the second parameter to retrieve the setting settingsToSendToThePrinter.put("device.friendly_name", null); // Pass in a value as the second parameter to set the setting settingsToSendToThePrinter.put("comm.baud", "14400"); // The map containing the results to each settings command Map results = null; try { results = SettingsSetter.process(ipAddress, settingsToSendToThePrinter); } catch (ConnectionException e) { e.printStackTrace(); } catch (SettingsException e) { e.printStackTrace(); } for (Map.Entry entry : results.entrySet()) { System.out.println("The setting " + entry.getKey() + " returned " + entry.getValue() + "."); } } } ``` -------------------------------- ### TcpStatusConnection Example Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/comm/TcpStatusConnection.html Example usage of TcpStatusConnection to establish a connection and retrieve printer settings. ```APIDOC ## TcpStatusConnection Example ### Description This example demonstrates how to establish a status-only TCP connection to a ZPL device and retrieve a printer setting using the SGD command. ### Method `sendJSONOverStatusChannel(String theIpAddress)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java new TcpStatusConnectionExample().sendJSONOverStatusChannel("1.2.3.4"); ``` ### Response #### Success Response (200) Prints the firmware version to the console. #### Response Example ``` The firmware version is : [firmware_version] ``` ### Error Handling Catches `ConnectionException` and prints the stack trace. ``` -------------------------------- ### GET /settings/all Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/device/Profile.html Retrieves all settings and their associated attributes from the printer profile. ```APIDOC ## GET /settings/all ### Description Retrieve all settings and their attributes contained in the current printer profile. ### Method GET ### Endpoint /settings/all ### Response #### Success Response (200) - **settings** (Map) - A map of setting IDs and their corresponding attributes. #### Response Example { "setting_id_1": { "attribute": "value" }, "setting_id_2": { "attribute": "value" } } ``` -------------------------------- ### Instantiate and Configure Setting Object Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/settings/setting Demonstrates how to instantiate the Setting class and configure its properties such as value, access permissions, and range validation. ```java import com.zebra.sdk.settings.Setting; // Instantiate the Setting class Setting setting = new Setting(); // Configure setting properties setting.setValue("100"); setting.setType("Integer"); setting.setRange("0-255"); setting.setAccess("RW"); // Validate a value against the defined range boolean isValid = setting.isValid("150"); ``` -------------------------------- ### Get Printer Status Messages (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/printerstatusmessages This example demonstrates how to retrieve human-readable status messages from a Zebra printer. It connects to the printer, gets the current status, and if the printer is not ready, it uses PrinterStatusMessages to obtain and print error messages. Requires the Zebra SDK for Android. ```java package test.zebra.sdk.printer.examples; import com.zebra.sdk.comm.Connection; import com.zebra.sdk.comm.ConnectionException; import com.zebra.sdk.comm.TcpConnection; import com.zebra.sdk.printer.PrinterStatus; import com.zebra.sdk.printer.PrinterStatusMessages; import com.zebra.sdk.printer.ZebraPrinter; import com.zebra.sdk.printer.ZebraPrinterFactory; import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException; public class PrinterStatusMessagesExample { public static void main(String[] args) throws Exception { Connection connection = new TcpConnection("192.168.1.100", TcpConnection.DEFAULT_ZPL_TCP_PORT); try { connection.open(); ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection); PrinterStatus printerStatus = printer.getCurrentStatus(); if (printerStatus.isReadyToPrint) { System.out.println("Ready To Print"); } else { PrinterStatusMessages statusMessage = new PrinterStatusMessages(printerStatus); String[] statusMessages = statusMessage.getStatusMessage(); String joinedStatusMessage = ""; for (int i = 0; i < statusMessages.length; i++) { joinedStatusMessage += statusMessages[i] + ";"; } System.out.println("Cannot Print: " + joinedStatusMessage); } } catch (ConnectionException e) { e.printStackTrace(); } catch (ZebraPrinterLanguageUnknownException e) { e.printStackTrace(); } finally { connection.close(); } } } ``` -------------------------------- ### Load Printer Backup (ProfileUtil) Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/comm/class-use/connectionexception Loads settings, alerts, and files from a backup file into a printer using the ProfileUtil class. Requires the path to the backup file. ```java void ProfileUtil.loadBackup(String pathToBackup) ``` ```java void ProfileUtil.loadBackup(String pathToBackup, boolean isVerbose) ``` -------------------------------- ### Get Zebra Printer Control Language (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/zebraprinter Example of how to get the printer control language (ZPL or CPCL) using the ZebraPrinterFactory and a TcpConnection. It demonstrates opening a connection, obtaining the printer instance, retrieving the language, and closing the connection. Handles potential connection and language unknown exceptions. ```Java package test.zebra.sdk.printer.examples; import com.zebra.sdk.comm.Connection; import com.zebra.sdk.comm.ConnectionException; import com.zebra.sdk.comm.TcpConnection; import com.zebra.sdk.printer.PrinterLanguage; import com.zebra.sdk.printer.ZebraPrinter; import com.zebra.sdk.printer.ZebraPrinterFactory; import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException; public class ZebraPrinterExample { public static void main(String[] args) throws Exception { Connection connection = new TcpConnection("10.0.1.18", TcpConnection.DEFAULT_ZPL_TCP_PORT); try { connection.open(); ZebraPrinter zPrinter = ZebraPrinterFactory.getInstance(connection); PrinterLanguage pcLanguage = zPrinter.getPrinterControlLanguage(); System.out.println("Printer Control Language is " + pcLanguage); connection.close(); } catch (ConnectionException e) { e.printStackTrace(); } catch (ZebraPrinterLanguageUnknownException e) { e.printStackTrace(); } finally { connection.close(); } } } ``` -------------------------------- ### Load Printer Configuration from Backup or Profile Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/printer/class-use/zebraprinterlanguageunknownexception Methods to apply settings, alerts, and files from a backup or profile file to a connected printer. These methods require a valid connection string and the path to the source file. ```Java PrinterUtil.loadBackup(connectionString, backupPath); PrinterUtil.loadBackup(connectionString, backupPath, isVerbose); PrinterUtil.loadProfile(connectionString, profilePath, filesToDelete); PrinterUtil.loadProfile(connectionString, profilePath, filesToDelete, isVerbose); ``` -------------------------------- ### Send and Get SGD Commands via Multichannel TCP Connection (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/SGD.html Illustrates how to use the SGD utility class with a MultichannelTcpConnection to interact with a Zebra printer. This example shows retrieving device information and printer settings over different channels (printing, status). ```Java package test.zebra.sdk.printer.examples; import com.zebra.sdk.comm.Connection; import com.zebra.sdk.comm.ConnectionException; import com.zebra.sdk.comm.MultichannelTcpConnection; import com.zebra.sdk.printer.SGD; public class SGDExample { public static void main(String[] args) { try { String ipAddress = "192.168.1.2"; sgdOverTcp(ipAddress); sgdOverMultiChannelNetworkConnection(ipAddress); } catch (ConnectionException e) { e.printStackTrace(); } } public static void sgdOverTcp(String ipAddress) throws ConnectionException { int port = 9100; Connection printerConnection = new TcpConnection(ipAddress, port); try { printerConnection.open(); SGD.SET("print.tone", "15", printerConnection); String printTone = SGD.GET("print.tone", printerConnection); System.out.println("SGD print.tone is " + printTone); } catch (ConnectionException e) { e.printStackTrace(); } finally { printerConnection.close(); } } private static void sgdOverMultiChannelNetworkConnection(String ipAddress) throws ConnectionException { // Create and open a connection to a Link-OS printer using both the printing and the status channel MultichannelTcpConnection printerConnection = new MultichannelTcpConnection(ipAddress, MultichannelTcpConnection.DEFAULT_MULTICHANNEL_PRINTING_PORT, MultichannelTcpConnection.DEFAULT_MULTICHANNEL_STATUS_PORT); try { printerConnection.open(); // Get an SGD, using the status channel String modelName = SGD.GET("device.product_name", printerConnection); System.out.println("SGD device.product_name is " + modelName); // Close the connection, and re-open it using only the status channel printerConnection.close(); printerConnection.openStatusChannel(); // Get an SGD, again using the status channel String printSpeed = SGD.GET("media.speed", printerConnection); System.out.println("The print speed is " + printSpeed); // Close the connection, and re-open it using only the printing channel printerConnection.close(); printerConnection.openPrintingChannel(); // Get an SGD, using the printing channel String mirrorFrequency = SGD.GET("ip.mirror.freq", printerConnection); System.out.println("The mirror frequency is " + mirrorFrequency); } catch (ConnectionException e) { e.printStackTrace(); } finally { printerConnection.close(); } } } ``` -------------------------------- ### POST /profile/create Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/printer/printerutil Creates a profile of printer settings, alerts, and files for cloning purposes, excluding conflicting network settings. ```APIDOC ## POST /profile/create ### Description Creates a profile of your printer's settings, alerts, and files for cloning to other printers. A profile contains setting values which can be used to clone another printer to match the original configuration. ### Method POST ### Endpoint /profile/create ### Parameters #### Request Body - **connectionString** (String) - Required - The connection string for the printer. - **profilePath** (String) - Required - The location where the profile will be stored. ### Request Example { "connectionString": "TCP:192.168.1.100:9100", "profilePath": "/sdcard/printer_profile.zprofile" } ### Response #### Success Response (200) - **status** (String) - Confirmation of profile creation. #### Response Example { "status": "success" } ``` -------------------------------- ### Initialize Profile Object Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/device/Profile.html Demonstrates the instantiation of a Profile object by providing the path to an existing .zprofile file. ```java import com.zebra.sdk.device.Profile; // Create a Profile object backed by an existing .zprofile file Profile profile = new Profile("/path/to/printer_profile.zprofile"); ``` -------------------------------- ### Establish Insecure Bluetooth Status Connection and Get Firmware Version (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/comm/BluetoothStatusConnectionInsecure.html This example demonstrates how to establish an insecure Bluetooth connection to a Link-OS printer using BluetoothStatusConnectionInsecure. It then uses SGD.GET to retrieve the 'appl.name' (firmware version) and prints it to the console. This connection is for status updates only and cannot be used for printing. ```java package test.zebra.android.comm.examples; import android.os.Looper; import com.zebra.sdk.comm.BluetoothStatusConnectionInsecure; import com.zebra.sdk.comm.Connection; import com.zebra.sdk.printer.SGD; public class BluetoothStatusConnectionInsecureExample { public static void main(String[] args) { BluetoothStatusConnectionInsecureExample example = new BluetoothStatusConnectionInsecureExample(); String theBtMacAddress = "00:11:BB:DD:55:FF"; example.sendJSONOverStatusChannel(theBtMacAddress); } private void sendJSONOverStatusChannel(final String theBtMacAddress) { new Thread(new Runnable() { public void run() { try { // Instantiate insecure connection for given Bluetooth® MAC Address. Connection thePrinterConn = new BluetoothStatusConnectionInsecure(theBtMacAddress); // Initialize Looper.prepare(); // Open the connection - physical connection is established here. thePrinterConn.open(); // This sends down JSON to the status channel to retrieve the 'appl.name' setting String firmwareVersion = SGD.GET("appl.name", thePrinterConn); System.out.println("The firmware version is : " + firmwareVersion); // Close the insecure connection to release resources. thePrinterConn.close(); Looper.myLooper().quit(); } catch (Exception e) { // Handle communications error here. e.printStackTrace(); } } }).start(); } } ``` -------------------------------- ### Establish Bluetooth Status Connection and Get Firmware Version (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/comm/BluetoothStatusConnection.html This example demonstrates how to establish a Bluetooth status-only connection to a printer using its MAC address and retrieve the 'appl.name' setting, which typically represents the firmware version. It utilizes the `BluetoothStatusConnection` class and the `SGD.GET` method. Ensure the Bluetooth device is discoverable and authentication is enabled. ```java package test.zebra.android.comm.examples; import android.os.Looper; import com.zebra.sdk.comm.BluetoothStatusConnection; import com.zebra.sdk.comm.Connection; import com.zebra.sdk.printer.SGD; public class BluetoothStatusConnectionExample { public static void main(String[] args) { BluetoothStatusConnectionExample example = new BluetoothStatusConnectionExample(); String theBtMacAddress = "00:11:BB:DD:55:FF"; example.sendJSONOverStatusChannel(theBtMacAddress); } private void sendJSONOverStatusChannel(final String theBtMacAddress) { new Thread(new Runnable() { public void run() { try { // Instantiate a status only connection for given Bluetooth® MAC Address. Connection thePrinterConn = new BluetoothStatusConnection(theBtMacAddress); // Initialize Looper.prepare(); // Open the connection - physical connection is established here. thePrinterConn.open(); // This sends down JSON to the status channel to retrieve the 'appl.name' setting String firmwareVersion = SGD.GET("appl.name", thePrinterConn); System.out.println("The firmware version is : " + firmwareVersion); // Close the connection to release resources. thePrinterConn.close(); Looper.myLooper().quit(); } catch (Exception e) { // Handle communications error here. e.printStackTrace(); } } }).start(); } } ``` -------------------------------- ### Initialize ZebraCertificateInfo Instance Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/certificate/zebracertificateinfo Demonstrates the instantiation of the ZebraCertificateInfo class to begin managing printer security credentials. ```java ZebraCertificateInfo certInfo = new ZebraCertificateInfo(); ``` -------------------------------- ### Manage Zebra Printer Profiles and Backups in Java Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/ProfileUtil.html Demonstrates how to use the ZebraPrinterLinkOs interface to perform profile operations such as creating profiles, restoring backups, and cloning printer configurations. The example uses a TcpConnection to communicate with the printer and handles common exceptions like ConnectionException and IOException. ```java package test.zebra.sdk.printer.examples; import java.io.IOException; import com.zebra.sdk.comm.ConnectionException; import com.zebra.sdk.comm.TcpConnection; import com.zebra.sdk.device.ZebraIllegalArgumentException; import com.zebra.sdk.printer.ZebraPrinterFactory; import com.zebra.sdk.printer.ZebraPrinterLinkOs; public class ProfileUtilExample { enum ProfileOperations { create_profile, restore_backup, clone_a_printer }; public static void main(String[] args) throws Exception { String pathToProfile = "C:\\MyNewProfile.zprofile"; ProfileOperations whatToDo = ProfileOperations.create_profile; TcpConnection connection = new TcpConnection("192.168.1.32", TcpConnection.DEFAULT_ZPL_TCP_PORT); try { connection.open(); ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.getLinkOsPrinter(connection); if (linkOsPrinter != null) { switch (whatToDo) { case create_profile: linkOsPrinter.createProfile(pathToProfile); break; case restore_backup: linkOsPrinter.loadBackup(pathToProfile); break; case clone_a_printer: linkOsPrinter.loadProfile(pathToProfile); break; } } } catch (ConnectionException | ZebraIllegalArgumentException | IOException e) { e.printStackTrace(); } finally { connection.close(); } } } ``` -------------------------------- ### GET /printer/snmp/community-name Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/printer/zebraprinterlinkos Retrieves the SNMP get community name configured on the printer. ```APIDOC ## GET /printer/snmp/community-name ### Description Fetches the current SNMP get community name string from the printer settings. ### Method GET ### Endpoint /printer/snmp/community-name ### Parameters None ### Response #### Success Response (200) - **communityName** (String) - The SNMP get community name. #### Response Example { "communityName": "public" } ``` -------------------------------- ### POST /settings/process Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/printer/SettingsSetter.html Sends a map of settings to a specified printer device and returns the updated values after verification. ```APIDOC ## POST /settings/process ### Description Sends a collection of settings to a target printer device. The method validates the settings and returns the current state of the settings after the update. ### Method POST ### Endpoint SettingsSetter.process(String destinationDevice, Map settingsToSet) ### Parameters #### Path Parameters - **destinationDevice** (String) - Required - The connection string for the target printer. #### Request Body - **settingsToSet** (Map) - Required - A map containing the key-value pairs of settings to be applied to the printer. ### Request Example { "destinationDevice": "192.168.1.100", "settingsToSet": { "device.friendly_name": "Warehouse_Printer_01", "ip.dhcp.enable": "on" } } ### Response #### Success Response (200) - **result** (Map) - The updated settings values retrieved from the printer after processing. #### Response Example { "device.friendly_name": "Warehouse_Printer_01", "ip.dhcp.enable": "on" } ``` -------------------------------- ### Get SNMP Community Name Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/printer/zebraprinterlinkos Retrieves the SNMP get community name configured on the printer. ```java String getGetCommunityName() ``` -------------------------------- ### ZebraP12Info Example Usage Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/certificate/zebrap12info An example demonstrating how to use the ZebraP12Info class to extract certificate information and store it on a Zebra printer. ```APIDOC ## Example: Using ZebraP12Info This example shows how to load a PKCS#12 file, extract certificate details, and then store these details along with the encrypted private key onto a Zebra Link-OS printer. ### Method `main` (static method within `ZebraP12InfoExample` class) ### Endpoint N/A (This is a client-side Java example) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```java public class ZebraP12InfoExample { public static void main(String[] args) throws Exception { InputStream p12InputStream = null; ZebraP12Info zebraP12Info = null; String p12FilePassword = "P12_PASSWORD"; String privateKeyEncryptionPassword = "1234"; try { p12InputStream = new FileInputStream("/path/to/file.p12"); zebraP12Info = new ZebraP12Info(p12InputStream, p12FilePassword); } catch (FileNotFoundException e) { System.out.println("Could not find the p12 file."); } catch (ZebraCertificateException e) { System.out.println("Failed to extract contents from the p12 file. Make sure the provided p12 file and password are valid."); } finally { if (p12InputStream != null) { try { p12InputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } DriverPrinterConnection conn = null; try { String caContent = zebraP12Info.getCaContent(); String clientCertificateContent = zebraP12Info.getCertificateContent(); String encryptedPrivateKeyContent = zebraP12Info.getEncryptedPrivateKeyContent(privateKeyEncryptionPassword, p12FilePassword); conn = new DriverPrinterConnection("myPrinterDriverName"); conn.open(); ZebraPrinterLinkOs linkosPrinter = ZebraPrinterFactory.getLinkOsPrinter(conn); linkosPrinter.storeFileOnPrinter(clientCertificateContent.getBytes(), ZebraCertificateInfo.CLIENT_CERT_NRD_PRINTER_FILE_NAME); linkosPrinter.storeFileOnPrinter(caContent.getBytes(), ZebraCertificateInfo.CA_CERT_NRD_PRINTER_FILE_NAME); linkosPrinter.storeFileOnPrinter(encryptedPrivateKeyContent.getBytes(), ZebraCertificateInfo.CLIENT_PRIVATE_KEY_NRD_PRINTER_FILE_NAME); linkosPrinter.setSetting("wlan.private_key_password", privateKeyEncryptionPassword); } catch (Exception e) { e.printStackTrace(); } finally { if (conn != null) { conn.close(); } } } } ``` ### Response #### Success Response (200) N/A (This is a client-side Java example, success is indicated by the absence of exceptions and successful file storage on the printer). #### Response Example N/A ``` -------------------------------- ### POST /device/profileToMirrorServer Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/index-all Initializes a profile storage operation to a mirror server. ```APIDOC ## POST /device/profileToMirrorServer ### Description Creates an instance to store a profile onto a mirror server. ### Method POST ### Endpoint /device/profileToMirrorServer ### Parameters #### Request Body - **profileData** (String) - Required - The profile configuration data to be stored. ### Request Example { "profileData": "..." } ### Response #### Success Response (200) - **message** (String) - Confirmation of the profile storage initiation. #### Response Example { "message": "Profile storage initialized" } ``` -------------------------------- ### Create Printer Backup in Java Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/printer/printerutil Creates a comprehensive backup of printer settings, alerts, and files to a specified path. The method requires a connection string and a destination path, automatically ensuring the file extension is .zprofile. ```java public static void createBackup(String connectionString, String profilePath) throws ConnectionException, java.io.IOException, ZebraPrinterLanguageUnknownException, ZebraIllegalArgumentException, NotALinkOsPrinterException ``` -------------------------------- ### SGD GET Command Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/SGD.html Retrieves the value of a specific printer setting using the SGD GET command. ```APIDOC ## GET SGD Setting ### Description Constructs an SGD GET command and sends it to the printer to retrieve a specific setting value. ### Method GET ### Parameters #### Request Body - **setting** (String) - Required - The name of the SGD setting to retrieve. - **printerConnection** (Connection) - Required - The active printer connection object. ### Request Example { "setting": "device.product_name", "printerConnection": "[Connection Object]" } ### Response #### Success Response (200) - **value** (String) - The value of the requested setting. #### Response Example { "value": "Zebra ZT410" } ``` -------------------------------- ### SGD GET Command Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/printer/SGD.html Constructs an SGD GET command and sends it to the printer. This method waits for a specified timeout for a response and returns the SGD setting's value. ```APIDOC ## SGD GET Command ### Description Constructs an SGD GET command and sends it to the printer. This method waits for a maximum of `maxTimeoutForRead` milliseconds for any data to be received. Once some data has been received it waits until no more data is available within `timeToWaitForMoreData` milliseconds. This method returns the SGD value associated with `setting` without the surrounding quotes. ### Method GET (Conceptual - actual implementation is a method call) ### Endpoint N/A (This is a method within the SDK) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java // Example usage within the SDK String settingValue = PrinterSGDCommands.GET(setting, printerConnection, maxTimeoutForRead, timeToWaitForMoreData); ``` ### Response #### Success Response (200) - **settingValue** (String) - The SGD setting's value without surrounding quotes. #### Response Example ```json { "settingValue": "example_value" } ``` ### Throws - `ConnectionException` - if an I/O error occurs ``` -------------------------------- ### Initialize ConnectionException Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/comm/ConnectionException.html Demonstrates the various ways to instantiate a ConnectionException, including providing a custom error message, a root cause, or a combination of both. ```java // Initialize with a message ConnectionException e1 = new ConnectionException("Connection failed"); // Initialize with a cause ConnectionException e2 = new ConnectionException(new Throwable("Socket timeout")); // Initialize with message and cause ConnectionException e3 = new ConnectionException("Connection failed", new Throwable("Socket timeout")); ``` -------------------------------- ### Extract and Deploy Certificates using ZebraP12Info Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/certificate/ZebraP12Info.html This example demonstrates how to initialize a ZebraP12Info object from an input stream, extract certificate contents, and store them on a Zebra printer using the Link-OS SDK. ```java import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import com.zebra.sdk.certificate.ZebraCertificateException; import com.zebra.sdk.certificate.ZebraCertificateInfo; import com.zebra.sdk.certificate.ZebraP12Info; import com.zebra.sdk.comm.DriverPrinterConnection; import com.zebra.sdk.printer.ZebraPrinterFactory; import com.zebra.sdk.printer.ZebraPrinterLinkOs; public class ZebraP12InfoExample { public static void main(String[] args) throws Exception { InputStream p12InputStream = null; ZebraP12Info zebraP12Info = null; String p12FilePassword = "P12_PASSWORD"; String privateKeyEncryptionPassword = "1234"; try { p12InputStream = new FileInputStream("/path/to/file.p12"); zebraP12Info = new ZebraP12Info(p12InputStream, p12FilePassword); } catch (FileNotFoundException e) { System.out.println("Could not find the p12 file."); } catch (ZebraCertificateException e) { System.out.println("Failed to extract contents from the p12 file."); } finally { if (p12InputStream != null) p12InputStream.close(); } DriverPrinterConnection conn = null; try { String caContent = zebraP12Info.getCaContent(); String clientCertificateContent = zebraP12Info.getCertificateContent(); String encryptedPrivateKeyContent = zebraP12Info.getEncryptedPrivateKeyContent(privateKeyEncryptionPassword, p12FilePassword); conn = new DriverPrinterConnection("myPrinterDriverName"); conn.open(); ZebraPrinterLinkOs linkosPrinter = ZebraPrinterFactory.getLinkOsPrinter(conn); linkosPrinter.storeFileOnPrinter(clientCertificateContent.getBytes(), ZebraCertificateInfo.CLIENT_CERT_NRD_PRINTER_FILE_NAME); linkosPrinter.storeFileOnPrinter(caContent.getBytes(), ZebraCertificateInfo.CA_CERT_NRD_PRINTER_FILE_NAME); linkosPrinter.storeFileOnPrinter(encryptedPrivateKeyContent.getBytes(), ZebraCertificateInfo.CLIENT_PRIVATE_KEY_NRD_PRINTER_FILE_NAME); linkosPrinter.setSetting("wlan.private_key_password", privateKeyEncryptionPassword); } catch (Exception e) { e.printStackTrace(); } finally { if (conn != null) conn.close(); } } } ``` -------------------------------- ### Send SGD GET command to printer Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/index-all Constructs and sends an SGD (Set-Get-Do) GET command to a connected printer. This is used to query specific printer settings or status information. ```java import com.zebra.sdk.printer.SGD; import com.zebra.sdk.comm.Connection; // Example usage of SGD.GET String response = SGD.GET("device.languages", connection); // Or with timeout parameters String responseWithTimeout = SGD.GET("device.languages", connection, 5000, 1000); ``` -------------------------------- ### Get SNMP Community Name (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/snmpprinter Retrieves the SNMP get community name configured for the device. This method is part of the Zebra Link-OS Android SDK. ```java public String getCommunityName() { // Implementation details to retrieve the SNMP get community name return "public"; } ``` -------------------------------- ### Initialize and Upload Profile to Mirror Server Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/device/profiletomirrorserver Demonstrates how to instantiate the ProfileToMirrorServer class with a local file path and execute the upload process to a specified FTP server using credentials. ```java import com.zebra.sdk.device.ProfileToMirrorServer; import java.util.List; // Initialize the profile handler ProfileToMirrorServer profileHandler = new ProfileToMirrorServer("/home/user/profile.zprofile"); // Upload to the mirror server List errors = profileHandler.sendToMirrorServer("ftp://server.address", "username", "password"); if (errors.isEmpty()) { System.out.println("Profile uploaded successfully."); } else { System.out.println("Errors occurred: " + errors); } ``` -------------------------------- ### Set SNMP Get Community Name (Java) Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/printer/zebraprinterlinkos Sets the SNMP Get Community Name for the printer. This method takes a String parameter representing the new community name. ```java void setGetCommunityName(String getCommunityName) ``` -------------------------------- ### Manage Zebra Printer Profiles and Backups in Java Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/profileutil Demonstrates how to use the ZebraPrinterLinkOs interface to perform profile operations such as creating a profile, restoring a backup, or cloning printer settings via a TCP connection. ```Java package test.zebra.sdk.printer.examples; import java.io.IOException; import com.zebra.sdk.comm.ConnectionException; import com.zebra.sdk.comm.TcpConnection; import com.zebra.sdk.device.ZebraIllegalArgumentException; import com.zebra.sdk.printer.ZebraPrinterFactory; import com.zebra.sdk.printer.ZebraPrinterLinkOs; public class ProfileUtilExample { enum ProfileOperations { create_profile, restore_backup, clone_a_printer }; public static void main(String[] args) throws Exception { String pathToProfile = "C:\\MyNewProfile.zprofile"; ProfileOperations whatToDo = ProfileOperations.create_profile; TcpConnection connection = new TcpConnection("192.168.1.32", TcpConnection.DEFAULT_ZPL_TCP_PORT); try { connection.open(); ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.getLinkOsPrinter(connection); if (linkOsPrinter != null) { switch (whatToDo) { case create_profile: linkOsPrinter.createProfile(pathToProfile); break; case restore_backup: linkOsPrinter.loadBackup(pathToProfile); break; case clone_a_printer: linkOsPrinter.loadProfile(pathToProfile); break; } } } catch (Exception e) { e.printStackTrace(); } finally { connection.close(); } } } ``` -------------------------------- ### Get Private Key Format (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/certificate/ZebraP12Info.html Retrieves the format of the private key. Similar to getting the algorithm, this method requires the PKCS12 password and supports specifying an alias for a particular private key. ```java String getPrivateKeyFormat(String p12Password) throws ZebraCertificateException ``` ```java String getPrivateKeyFormat(String alias, String p12Password) throws ZebraCertificateException ``` -------------------------------- ### Initialize ZebraP12Info Constructor (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/certificate/ZebraP12Info.html Constructs a ZebraP12Info object by wrapping a PKCS12 keystore stream. It requires the stream and its corresponding password. The constructor can throw a ZebraCertificateException if the stream is inaccessible or the password is incorrect. ```java public ZebraP12Info(java.io.InputStream pkcs12Stream, String p12Password) throws ZebraCertificateException ``` -------------------------------- ### Profile Constructor and Methods (Java) Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/device/profile Provides details on the constructor and various methods available in the Profile class. These methods allow for adding firmware, supplements, configuring alerts, deleting files, downloading fonts, retrieving settings, and managing printer objects. ```java public Profile(String pathToProfile) void addFirmware(String pathToFirmwareFile) void addFirmware(String firmwareFileName, byte[] firmwareFileContents) void addSupplement(byte[] supplementData) void configureAlert(PrinterAlert alert) void configureAlerts(java.util.List alerts) void deleteFile(String filePath) void downloadTteFont(java.io.InputStream sourceInputStream, String pathOnPrinter) void downloadTteFont(String sourceFilePath, String pathOnPrinter) void downloadTtfFont(java.io.InputStream sourceInputStream, String pathOnPrinter) void downloadTtfFont(String sourceFilePath, String pathOnPrinter) java.util.Map getAllSettings() java.util.Map getAllSettingValues() java.util.Map getArchivableSettingValues() java.util.Set getAvailableSettings() java.util.Map getClonableSettingValues() java.util.List getConfiguredAlerts() String getFirmwareFilename() void getObjectFromPrinter(java.io.OutputStream destinationStream, String filePath) byte[] getObjectFromPrinter(String filePath) void getObjectFromPrinterViaFtp(java.io.OutputStream destinationStream, String filePath, String ftpPassword) byte[] getObjectFromPrinterViaFtp(String filePath, String ftpPassword) byte[] getPrinterDownloadableObjectFromPrinter(String filePath) Setting getSetting(String settingId) String getSettingRange(String settingId) java.util.Map getSettingsValues(java.util.List listOfSettings) String getSettingType(String settingId) String getSettingValue(String settingId) ``` -------------------------------- ### Send SGD GET Command to Printer (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/comm/class-use/connectionexception Constructs and sends a Set-Get-Do (SGD) GET command to the printer to retrieve a specific setting. This method returns the setting's value as a String and allows for configurable read timeouts. ```java static String SGD.GET(String setting, Connection printerConnection) static String SGD.GET(String setting, Connection printerConnection, int maxTimeoutForRead, int timeToWaitForMoreData) ``` -------------------------------- ### POST /process Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/printer/settingssetter Sends a map of settings to a specified printer device and returns the updated values after verification. ```APIDOC ## POST /process ### Description Sends the provided settings map to the destination printer and returns the updated setting values. It is recommended to bundle all settings into a single call to minimize communication overhead. ### Method POST ### Endpoint SettingsSetter.process(String destinationDevice, Map settingsToSet) ### Parameters #### Path Parameters - **destinationDevice** (String) - Required - The connection string for the target printer. #### Request Body - **settingsToSet** (Map) - Required - A map containing the setting keys and their desired values. ### Request Example { "destinationDevice": "TCP:192.168.1.100:9100", "settingsToSet": { "device.friendly_name": "Warehouse_Printer_01", "media.type": "label" } } ### Response #### Success Response (200) - **result** (Map) - The updated settings values retrieved from the printer after processing. #### Response Example { "device.friendly_name": "Warehouse_Printer_01", "media.type": "label" } ``` -------------------------------- ### GET /status Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/weblink/weblinkconfigurator Retrieves the status of the Weblink configuration task. ```APIDOC ## GET /status ### Description Returns the `ConfigurationStatus` of the weblink configuration task. ### Method GET ### Endpoint `/status` ### Parameters (None) ### Request Example (Not applicable) ### Response #### Success Response (200) - **ConfigurationStatus** (ConfigurationStatus) - Returns the status of the current configuration task. #### Response Example ```json { "status": "SUCCESS" } ``` ``` -------------------------------- ### Load Printer Profile (ProfileUtil) Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/comm/class-use/connectionexception Loads settings, alerts, and files from a profile file into a printer using the ProfileUtil class. Requires the path to the profile file and options for file deletion. ```java void ProfileUtil.loadProfile(String pathToProfile) ``` ```java void ProfileUtil.loadProfile(String pathToProfile, FileDeletionOption filesToDelete, boolean isVerbose) ``` -------------------------------- ### GET /currentState Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/weblink/weblinkconfigurator Retrieves the current state of the Weblink configuration. ```APIDOC ## GET /currentState ### Description Returns the current `WeblinkConfigurationState`. ### Method GET ### Endpoint `/currentState` ### Parameters (None) ### Request Example (Not applicable) ### Response #### Success Response (200) - **WeblinkConfigurationState** (WeblinkConfigurationState) - The current configuration state. #### Response Example ```json { "state": "CONFIGURED" } ``` ``` -------------------------------- ### Print Configuration and Directory Labels Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/comm/class-use/connectionexception Methods to trigger the printing of configuration, network configuration, and directory listing labels. These utilities support both direct connection strings and standard tool-based triggers. ```Java PrinterUtil.printConfigLabel(connectionString); PrinterUtil.printDirectoryLabel(connectionString); PrinterUtil.printNetworkConfigLabel(connectionString); ToolsUtil.printConfigurationLabel(); ToolsUtilLinkOs.printDirectoryLabel(); ToolsUtilLinkOs.printNetworkConfigurationLabel(); ``` -------------------------------- ### Get SGD Setting (Custom Timeout) - Java Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/SGD.html Constructs and sends an SGD GET command, waiting for a response within specified timeouts. Returns the SGD value associated with the setting, without surrounding quotes. ```java public static String GET(String setting, Connection printerConnection, int maxTimeoutForRead, int timeToWaitForMoreData) throws ConnectionException ``` -------------------------------- ### Get SGD Setting (Default Timeout) - Java Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/SGD.html Constructs and sends an SGD GET command, waiting for a response within default timeouts. Returns the SGD value associated with the setting, without surrounding quotes. ```java public static String GET(String setting, Connection printerConnection) throws ConnectionException ``` -------------------------------- ### Load Printer Profile (Java) Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/printer/printerutil Loads settings, alerts, and files from a profile onto the printer. Overloaded methods allow for different configurations, including verbose output. ```Java static void loadProfile(String connectionString, String profilePath, FileDeletionOption filesToDelete) static void loadProfile(String connectionString, String profilePath, FileDeletionOption filesToDelete, boolean isVerbose) ``` -------------------------------- ### Printer File Management Example (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/PrinterUtil.html Demonstrates how to use PrinterUtil to send file content, list files on the printer, and delete files. It includes examples for both silent and verbose deletion. Requires a connection to a Zebra printer. ```java package test.zebra.sdk.printer.examples; import java.io.IOException; import com.zebra.sdk.comm.ConnectionException; import com.zebra.sdk.device.ZebraIllegalArgumentException; import com.zebra.sdk.printer.NotALinkOsPrinterException; import com.zebra.sdk.printer.PrinterUtil; import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException; public class PrinterUtilExample { private static final String CONNECTION_STRING = "172.30.16.135"; public static void main(String[] args) throws ConnectionException, IOException, ZebraIllegalArgumentException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException { // Create a few files on the printer sendContentsExample(); // List the files just created listFilesExample(); // Silently delete some of the files deleteFilesExample(); // List the remaining files listFilesExample(); // Verbosely delete the rest of the files deleteFilesVerboseExample(); // List the remaining files listFilesExample(); } private static void sendContentsExample() throws ConnectionException, IOException { PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST1.ZPL^FO100,100^A0N,30,30^FDZSDK_Test1.zpl^FS^XZ"); PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST2.ZPL^FO100,100^A0N,30,30^FDZSDK_Test2.zpl^FS^XZ"); PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST3.ZPL^FO100,100^A0N,30,30^FDZSDK_Test3.zpl^FS^XZ"); PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST4.ZPL^FO100,100^A0N,30,30^FDZSDK_Test4.zpl^FS^XZ"); PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST11.ZPL^FO100,100^A0N,30,30^FDZSDK_Test11.zpl^FS^XZ"); PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST12.ZPL^FO100,100^A0N,30,30^FDZSDK_Test12.zpl^FS^XZ"); PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST22.ZPL^FO100,100^A0N,30,30^FDZSDK_Test22.zpl^FS^XZ"); PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST33.ZPL^FO100,100^A0N,30,30^FDZSDK_Test33.zpl^FS^XZ"); PrinterUtil.sendContents(CONNECTION_STRING, "^XA^DFR:ZSDK_TEST44.ZPL^FO100,100^A0N,30,30^FDZSDK_Test44.zpl^FS^XZ"); } private static void listFilesExample() throws ConnectionException, ZebraIllegalArgumentException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException { String[] filesOnE = PrinterUtil.listFiles(CONNECTION_STRING, "R:ZSDK_TEST*.* "); System.out.println("--- List of Files on R: ---"); for (String thisFile : filesOnE) { System.out.println(" - " + thisFile); } System.out.println("--- End of List ---"); } private static void deleteFilesExample() throws ConnectionException, ZebraPrinterLanguageUnknownException, NotALinkOsPrinterException { System.out.println("Deleting R:ZSDK_TEST1*.ZPL..."); PrinterUtil.deleteFile(CONNECTION_STRING, "R:ZSDK_TEST1*.ZPL"); } private static void deleteFilesVerboseExample() throws ConnectionException, ZebraPrinterLanguageUnknownException, ZebraIllegalArgumentException, NotALinkOsPrinterException { System.out.println("Verbosely Deleting R:ZSDK_TEST*.ZPL..."); String[] filesDeleted = PrinterUtil.deleteFileReportDeleted(CONNECTION_STRING, "R:ZSDK_TEST*.ZPL"); for (String thisDeletedFile : filesDeleted) { System.out.println(" - " + thisDeletedFile + " deleted"); } } } ``` -------------------------------- ### Load Printer Backup (PrinterUtil) Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/comm/class-use/connectionexception Loads settings, alerts, and files from a backup file into a printer using the PrinterUtil class. Requires a connection string, the path to the backup file, and an optional verbose flag. ```java static void PrinterUtil.loadBackup(String connectionString, String backupPath) ``` ```java static void PrinterUtil.loadBackup(String connectionString, String backupPath, boolean isVerbose) ``` -------------------------------- ### Android Multicast Lock Example (Java) Source: https://techdocs.zebra.com/link-os/2-13/android/content/com/zebra/sdk/printer/discovery/NetworkDiscoverer.html An example demonstrating how to obtain and manage a multicast lock on Android, which is necessary for the NetworkDiscoverer.multicast method to function correctly. It includes setting up the lock, acquiring it, performing discovery, and releasing the lock. ```Java package test.zebra.sdk.printer.discovery.examples; import android.app.Activity; import android.content.Context; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager.MulticastLock; import android.os.Bundle; import com.zebra.sdk.printer.discovery.DiscoveredPrinter; import com.zebra.sdk.printer.discovery.DiscoveryException; import com.zebra.sdk.printer.discovery.DiscoveryHandler; import com.zebra.sdk.printer.discovery.NetworkDiscoverer; public class NetworkDiscovererAndroidMulticastExample extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int multicastHops = 5; WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); MulticastLock lock = wifi.createMulticastLock("wifi_multicast_lock"); lock.setReferenceCounted(true); lock.acquire(); try { NetworkDiscoverer.multicast(new DiscoveryHandler() { public void foundPrinter(DiscoveredPrinter printer) { System.out.println("Found a printer with address : " + printer.address); } public void discoveryFinished() { System.out.println("Discovery finished"); } public void discoveryError(String message) { System.out.println("Discovery error! - " + message); } }, multicastHops); } catch (DiscoveryException e) { e.printStackTrace(); } lock.release(); } } ``` -------------------------------- ### ProfileUtil Methods Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/index-all Methods for creating and managing printer profiles. ```APIDOC ## ProfileUtil Methods ### Description Interface methods for creating and saving printer profiles for later restoration or cloning. ### Methods - **createBackup(String profileName)** - **createProfile(String profileName)** - **createProfile(OutputStream outputStream)** ### Parameters #### createBackup(String profileName) - **profileName** (String) - The name for the backup profile. #### createProfile(String profileName) - **profileName** (String) - The name for the profile. #### createProfile(OutputStream outputStream) - **outputStream** (OutputStream) - The stream to write the profile data to. ``` -------------------------------- ### Profile Constructor Source: https://techdocs.zebra.com/link-os/2-13/android_btle/content/com/zebra/sdk/device/Profile.html Creates a Profile object backed by an existing .zprofile file. This constructor requires the path to the profile file. It throws a FileNotFoundException if the specified file does not exist. ```java public Profile(String pathToProfile) throws java.io.FileNotFoundException ```