Documente Academic
Documente Profesional
Documente Cultură
XCheng POS projects built-in thermal printer, allowing App to print directly out of thermal
small ticket.
App developers can communicate with the built-in thermal printer in two ways:
1. Connect the printer via AIDL
2. Connect the printer via Bluetooth
AIDL is the abbreviation of the Android Interface Definition language, which is a description
language for the Android internal process communication interface,through which we can define
the communication interface between processes. AIDL provide packaged common print
instruction to facilitate developers to quickly access XCheng printer also supports "ESC / POS "
instruction set.
The establishment of the connection can be divided into the following five steps:
1. Add the AIDL file that came with the resource file in your project:
(1) in src to establish com.xcheng.printerservice package
(2) to join IPrinterCallback.aidl IPrinterService.aidl 2 files.
2. Implement the ServiceConnection in the code class that controls the printing.
3. Call bindService () and pass it in the ServiceConnection implementation.
Note: bindservice is a non-blocking call, which means that after the completion of the call is
not immediately bound successfully, must be serviceConnected prevail.
4. In the ServiceConnection.onServiceConnected () implementation, you will receive an
IBinder instance (called Service). Call IPrinterService.Stub.asInterface (service) to convert the
parameters to the IPrinterService type.
5. Now you can call the IPrinterService interface defined in the various methods to print.