Printer
Create printer
A printer is needed to print assets.
To create a SDKPrinter
, use the SDKPrinterFactory.createPrinter
. This method need a SDKPrinterListener
implementation, that is used to handle different states in print process.
Note:: This print process will replace to previous print process defined for MoreFun and Urovo SmartPOS.
printer = SDKPrinterFactory.createPrinter(object : SDKPrinterListener {
override fun onPrintStateChanged(state: SDKPrintState) {
handlePrintState(state) // define this function to handle print states
}
override fun onPrinterStateChanged(state: SDKPrinterState) {
handlePrinterState(state) // define this function to handle printer states
}
})
Printer can be aborted to cancel print process, using:
printer.abort()
There are some print states that will be explained.
Provide a device
Provide a device which was previously scanned. This device must be compatible with print process.
Call the method provideDevice
in SDKPrintState.DeviceRequired
state.
fun handlePrintState(state: SDKPrintState) {
when (state) {
is SDKPrintState.DeviceRequired -> {
state.provideDevice(selectedDevice) // device previously found by the scanner
}
...
}
}
Provide an asset to print
Provide an asset to be printed. Asset will be a FileWrapper
implementation or a Bitmap
.
Call the method print
in SDKPrintState.ReadyToPrint
state.
fun handlePrintState(state: SDKPrintState) {
when (state) {
is SDKPrintState.ReadyToPrint -> {
state.print(bitmap) // Bitmap or FileWrapper to be printed
}
...
}
}
Print again
When a print has been success, you can print an asset again.
Call the method printAgain
in SDKPrintState.SuccessfulPrint
state to print again. This method will trigger SDKPrintState.ReadyToPrint
state again.
Otherwise, you can finish print calling method finish
in SDKPrintState.SuccessfulPrint
. This method will trigger SDKPrintState.PrintCompleted
fun handlePrintState(state: SDKPrintState) {
when (state) {
is SDKPrintState.SuccessfulPrint -> {
state.printAgain()
// state.finish()
}
is SDKPrintState.PrintCompleted -> {
// trigger with state.finish()
}
...
}
}
Print error
During a print process, two kind of errors can occur: recoverable and not recoverable. In the recoverable, it’s possible to retry the print calling the associate callback. In the not recoverable errors, print finish and it's necessary to create another print process.
Check whether state is SDKPrintState.RecoverableError
or SDKPrintState.NonRecoverableError
.
fun handlePrintState(state: SDKPrintState) {
when (state) {
is SDKPrintState.RecoverableError -> {
...
state.recover() //if you want try recover an error
}
is SDKPrintState.NonRecoverableError -> {
//print finish by an error
}
...
}
}