【Android】Android集成芯烨云打印机实现打印票据
⽂章⽬录
【Android】Android 集成芯烨云打印机实现打印票据
1、集成芯烨云依赖
打开官⽹,下载对应的依赖模块,,安卓和Java都下载Java版本的,下载完成之后,全部复制到项⽬⾥⾯,懒得打包官⽹提供的源码了
2、配置账号秘钥
到util下⾯的Config,修改成⾃⼰的账号,key
3、编写打印接⼝
import Intent;
import Build;
import JavascriptInterface;
import Toast;
import RequiresApi;
import JSON;
import JSONObject;
import MainActivity;
import BizOrderInfoVo;
import PrintService;
import Config;
import NoteFormatter;
import PrintRequest;
import StringUtils;
import SimpleDateFormat;
import Date;
import List;
import Collectors;
public class BusinessService {
private static final PrintService printService =new PrintService();
/**
* 配送单
*
* @param param
*/
@RequiresApi(api = Build.VERSION_CODES.N)
@JavascriptInterface
public void deliverOrderPrinter(String param)throws Exception {
System.out.println("配送单参数:"+ param);
if(StringUtils.isEmpty(param)){
Toast.makeText(MainActivity.CONTEXT,"配送单不能为空", Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.CONTEXT,"配送单不能为空", Toast.LENGTH_SHORT).show();
return;
}
JSONObject map = JSONObject.parseObject(param);
String printerNumber = String.("printerNumber"));
System.out.println("打印机编号:"+ printerNumber);
if(StringUtils.isEmpty(printerNumber)){
Toast.makeText(MainActivity.CONTEXT,"打印机编号不能为空", Toast.LENGTH_SHORT).show();
return;
}
String[] printer = printerNumber.split(",");
PrintRequest request =new PrintRequest();
request.setMode(0);
for(int i =0; i < printer.length; i++){
List<BizOrderInfoVo> totalList = JSON.parseArray((String) ("orderInfoVoList"), BizOrderInfoVo.class);
StringBuilder content =new StringBuilder();
// 打印配送单
content.append("<CB>配送单<BR></CB>");
content.peat("-",32)).append("<BR>");
content.append("部门")
.peat(" ",12))
.append("位置").peat(" ",6))
.append("份数").peat(" ",2))
.append("<BR>");
content.peat("-",32)).append("<BR>");
for(BizOrderInfoVo total : totalList){
if(StringUtils.DeptName())){
total.setDeptName("未设置");
}
if(StringUtils.DeptAddress())){
total.setDeptAddress("未设置");
}
content.append(NoteFormatter.DeptName(), DeptAddress(), CountNumber()));
安卓下载
}
content.peat("-",32)).append("<BR>");
int sum = totalList.stream().collect(Collectors.summingInt(BizOrderInfoVo::getCountNumber));
content.append(NoteFormatter.formatPrintOrderItemMy("总计","", sum));
content.peat("-",32)).append("<BR>");
content.append("<L>打印时间:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"<BR></L>");
content.append("<L>部门签字:<BR></L>");
content.peat("-",32)).append("<BR>");
request.setCopies(2);
request.setSn(printer[i]);
request.String());
printService.print(request);
content.setLength(0);
// 打印配送分单
for(BizOrderInfoVo total : totalList){
content.append("<CB>配送分单<BR></CB>");
content.append("<CB>"+ DeptName()+"<BR></CB>");
content.peat("-",32)).append("<BR>");
content.append("<L>部门名称:"+ DeptName()+"<BR></L>");
content.append("<L>部门位置:"+ DeptAddress()+"<BR></L>");
content.append("<L>总份数:"+ CountNumber()+"<BR></L>");
content.peat("-",32)).append("<BR>");
content.append("电话")
.peat(" ",12))
.
append("姓名").peat(" ",6))
.append("数量").peat(" ",2))
.append("<BR>");
content.peat("-",32)).append("<BR>");
List<BizOrderInfoVo> orderList = OrderInfoVoList();
for(BizOrderInfoVo order : orderList){
if(StringUtils.UserName())){
if(StringUtils.UserName())){
total.setUserName("未设置");
}
if(StringUtils.NickName())){
total.setNickName("未设置");
}
content.append(NoteFormatter.UserName(), NickName(), CountNumber()));
}
content.peat("-",32)).append("<BR>");
int orderSum = orderList.stream().collect(Collectors.summingInt(BizOrderInfoVo::getCountNumber));
content.append(NoteFormatter.formatPrintOrderItemMy("总计","", orderSum));
content.peat("-",32)).append("<BR>");
content.append("<L>打印时间:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"<BR></L>");
content.append("<L>部门签字:<BR></L>");
content.peat("-",32)).append("<BR>");
}
request.setCopies(1);
request.setSn(printer[i]);
request.String());
printService.print(request);
}
}
}
3、MainActivity初始化接⼝
// 初始化业务接⼝
BusinessService businessService =new BusinessService();
webView.addJavascriptInterface(businessService,"businessService");
4、Uniapp调⽤⽅法
在接⼝⽅法已经使⽤了@JavascriptInterface注解,可以使⽤JavaScript直接调⽤
/**
* 打印配送单
*/
function deliverOrderPrinter(content){
window.businessService.deliverOrderPrinter(content);
}
技术分享区

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。