Recently received a request to use Android to initiate a print task, connect the printer via Bluetooth. The conditions are as follows:
Printer: Nanjing Fujitsu dpk760e, with Bluetooth function
Android Phone: normal phone, Android 4.4 version, with Bluetooth function
Specific operation:
1. Bluetooth handshake
2. Establishing a communication connection
3. Send Print Instructions
-------------------
Use the official provided examples can support the 1th, 2 steps, the difficulty is the third step. The official provided example does not manipulate the location coordinates of the print, after repeated functions, the following commands are obtained:
A. Roll paper, move the paper operation, equivalent to the Y axis, but this is a relative position, that is, the hair once moved 1 cm, and, can not be reversed.
B. Horizontal movement of the print coordinates, absolute position, equivalent to moving the x axis
C. Print output text
D. end of printing.
-------------------
Because the y-axis is a relative coordinate, coding can be cumbersome. I think of a way to create a location description (template) of all the content that needs to be printed, put it in a collection, sort it, sort it in ascending order of y size, and then sort by x in ascending order. When you are finished, define a y_cursor record to hold the current absolute position coordinates.
Demo download
Android Development (42) using Andorid to operate a Bluetooth printer