Android Port Program Manual
Android Port Program Manual
Android Port Program Manual
v2.2.4
Contents
Android Port Program Manual ............................................................................................................1
Bluetooth, Wi-Fi, USB, Serial .............................................................................................................. 1
1. Instruction ...............................................................................................................................3
1.1. initialization ..................................................................................................................3
1.2. Create a printer connection .........................................................................................3
1.3. Print ..............................................................................................................................3
1.4. Close the connection ................................................................................................... 3
2. POSConnect ............................................................................................................................ 3
2.1. init ................................................................................................................................ 4
2.2. createDevice ................................................................................................................ 4
2.3. connectMac ................................................................................................................. 4
2.4. exit ................................................................................................................................5
2.5. getUsbDevices ............................................................................................................. 5
2.6. getSerialPort ................................................................................................................ 5
3. IDeviceConnection .................................................................................................................. 5
3.1. connect ........................................................................................................................ 6
3.2. close ............................................................................................................................. 6
3.3. sendData ...................................................................................................................... 6
3.4. readData ...................................................................................................................... 7
1. Instruction
This Android Port Program Manual describes how to connect the printer through Bluetooth, USB,
Wi-Fi and serial ports and send content to the printer.
1.1. initialization
POSConnect.init(appContext)
1.3. Print
printer.printString("test ~")
connect.close()
2. POSConnect
This class is used to connect printers.Constant variable are defined in POSConnect class.
2.1. init
This function is used for SDK initialization.It is recommended to call in the onCreate function of
the application class.
static void init(Context appContext)
[Parameter]
appContext
Context of application
2.2. createDevice
[Return]
Connect Object
2.3. connectMac
Connect to the device through the MAC address, only support the network port of the receipt
printer.
static IDeviceConnection connectMac(String mac, IPOSListener listener)
[Parameter]
mac
printer mac address
listener
Connect the status listener.
code Description
CONNECT_SUCCESS Connection successful
CONNECT_FAIL Connection failed
CONNECT_INTERRUPT Disconnected
SEND_FAIL fail in send
USB_ATTACHED USB Attached
USB_DETACHED USB Detached
BLUETOOTH_INTERRUPT Bluetooth Interrupt
[Return]
Connect Object
2.4. exit
2.5. getUsbDevices
[Parameter]
context
Context
[Return]
USB port pathname list.
2.6. getSerialPort
[Return]
Serial port path list
3. IDeviceConnection
The interface class connecting the device, which is used to send data to the printer or read the
data returned by the printer.Available through POSConnect.createDevice(deviceType).
3.1. connect
3.2. close
3.3. sendData
[Parameter]
data
Byte array to be sent
datas
Byte array collection to be sent
3.4. readData
This function is used to read the data returned from the printer.
void readData(int timeout, IDataCallback callback)
void readData(IDataCallback callback)
byte[] readSync(int timeout)
Synchronous reading may block the UI thread.
[Parameter]
timeout
Read timeout, in milliseconds. The default is 5000.
callback
Data callback
public interface IDataCallback {
void receive(byte[] data);
}