wmpf.printer
Sends text content to the device's printer service - Asynchronous return
Example Code
wmpf.printer({
data: [ // All information in data will be passed through to the business side, corresponding to the raw_data in Intent Extra Data
{
"type": "base_string",
"content": "XXXX Information Technology Co., Ltd.",
"style": {
"fontSize": 30,
"bold": 1
}
},
{
"type": "base_string",
"content": "Customer Information",
"style": {
"fontSize": 25,
"bold": 1
}
},
{
"type": "both_side",
"content": {
"left": "Customer Name",
"right": "Kommi"
},
"style": {
"fontSize": 20,
"bold": 0
}
},
{
"type": "base_string",
"content": "Other Information",
"style": {
"fontSize": 25,
"bold": 1
}
},
{
"type": "both_side",
"content": {
"left": "Verification Store",
"right": "Weike 407 National Road Store"
},
"style": {
"fontSize": 20,
"bold": 0
}
},
{
"type": "both_side",
"content": {
"left": "Verification Code",
"right": "5665470281092409"
},
"style": {
"fontSize": 20,
"bold": 0
}
},
{
"type": "barcode",
"content": "5665470281092409",
"barCodeOption": {
"barWidth": "normal",
}
}
],
success: (res) => {
console.log(res)
},
fail: (res) => {
console.log(res)
}
})
WMPF Client-side Data Processing
After receiving the print request issued by the developer on the frontend, the WMPF framework notifies the WMPF Client side via a startAcitivtyForResult call. Therefore, the WMPF Client side must register an Activity with the Action set to com.tencent.wmpf.action.WMPF_PRINTER to receive the pass-through call data from the WMPF framework.
The call data is stored in the Intent and can be retrieved in the Activity using getIntent(). The data contained in the Intent is described as follows:
| Parameter | Type | Description |
|---|---|---|
| raw_data | string | The raw print data passed through, corresponding to the data in the data field of the frontend call |
| key_time_stamp | int | The timestamp of the call |
| key_token | string | Call verification, formatted as MD5 ( appid + "_" + key_time_stamp ) |
Callback
After the WMPF Client processes the print request, it must invoke a callback to the WMPF framework to notify that the entire invocation flow has been completed, thereby ensuring a proper frontend callback. The callback parameters are also included in the Intent and passed via setResult(resultCode, intent). The resultCode is set based on the actual invocation result. The callback data contained in the Intent is described as follows:
| Parameter | Type | Description |
|---|---|---|
| result_code | int | Print result feedback value, customized by the developer. The value is passed through to the frontend. |