C API Samples: Difference between revisions
No edit summary |
|||
Line 1: | Line 1: | ||
== JNI Samples == | == JNI Samples == | ||
=== Printer === | === Printer === | ||
The calling sequence is open>query_status>begin>write>end>close. Please notice that: | |||
* [[write]] method is used for printing content. | |||
* print content should be between [[begin]] method and [[end]] method. | |||
* [[query_status]] should be between [[open]] method and [[close]] method, but should not be between [[begin]] method and [[end]] method | |||
The following code shows how to print some content: | The following code shows how to print some content: | ||
int result = PrinterInterface.open(); | int result = PrinterInterface.open(); | ||
Line 38: | Line 43: | ||
} | } | ||
PrinterInterface.close(); | PrinterInterface.close(); | ||
=== Contactless card reader === | === Contactless card reader === |
Revision as of 09:35, 8 April 2018
JNI Samples
Printer
The calling sequence is open>query_status>begin>write>end>close. Please notice that:
- write method is used for printing content.
- print content should be between begin method and end method.
- query_status should be between open method and close method, but should not be between begin method and end method
The following code shows how to print some content:
int result = PrinterInterface.open(); if (result <0){ return; } Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.printer_barcode_low); byte[] arryBeginText = null; byte[] arryEndText = null; try { arryBeginText = mContext.getResources().getString(R.string.print_QR_code).getBytes("GB2312"); arryEndText = "This is a Bitmap of Barcode".getBytes("GB2312"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } int result = PrinterInterface.begin(); if (result <0){ return; } result = PrinterInterface.write(arryBeginText, arryBeginText.length); if (result <0){ return; } // print line break writeLineBreak(2); PrinterBitmapUtil.printBitmap(bitmap, 0, 0, true); // print line break writeLineBreak(2); // print text write(arryEndText); // print line break writeLineBreak(2); result = PrinterInterface.end(); if (result <0){ return; } PrinterInterface.close();