How to print an Image using USB Connection - Zebra GK420d

// Expert user has replied.
J Janmejoy Layek 3 years 6 months ago
154 2 0

I am using ZSDK_ANDROID_API.jar file. I tried the below code to Print data using USB Connection. It sends the signal to Zebra using the USB connection, However, the Printer prints empty page and getting the error - Could not disconnect from device: USB Connection failed to release. Please advise.
Code link - http://techdocs.zebra.com/link-os/2-14/android/
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100 , bos);
byte[] bitmapData = bos.toByteArray();
ByteArrayInputStream bs = new ByteArrayInputStream(bitmapData);
try {
conn = discoveredPrinterUsb.getConnection();
conn.open();
//conn.write("~WC".getBytes());
conn.write(bs);
} catch (ConnectionException e) {
Toast.makeText(getApplicationContext(), e.getMessage() + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
} finally {
if (conn != null) {
try {
conn.close();
} catch (ConnectionException e) {
e.printStackTrace();
}
}
}
} else {
Toast.makeText(getApplicationContext(), "No permission to communicate", Toast.LENGTH_LONG).show();
}

Please Register or Login to post a reply

2 Replies

S Steven Si

To print image, you can use the printImage() in ZebraPrinter class, or use the API in GraphicsUtil class. If you want to use the raw API, like conn.write(), you need to make sure that the content in the write statement meets the ZPL spec for image print.

D Dmitry Prokhorov

Hello Janmejoy,
Please, use example applications source code from installed Link OS SDK.
Dmitry Prokhorov
Software Engineer, Kutir Mobility
Posted on behalf of Zebra Technologies
 

CONTACT
Can’t find what you’re looking for?