Android设备打印比较麻烦,一般设备厂商都提供原生app开发的SDK,我们web开发者为难了,不会原生开发啊
给大家提供一个思路,实现web加壳,利用打印浏览器实现
简单来说就是把我们的web页面嵌入浏览器中
web页面的打印功能通过js与浏览器互动
浏览器通过调用硬件SDK实现打印
1、机器安装最新SDK,已安装请忽略
2、下载安装本页下载连接中的打印浏览器并安装
3、对照下方事例代码,修改web页面打印功能
4、打印浏览器中打开web页面,测试打印功能
5、默认主页可以在SD卡根目录修改homepage.txt中的网址
*以上所有步骤必须在智谷联产品上使用,详情咨询销售工程师
软件支持android网页打印工具,安卓网页打印工具,h5页面打印,浏览器打印,js打印工具
web页面按照如下事例,修改打印函数代码,调用打印API即可完成打印功能
<html>
<head>
<link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
<script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
div {
margin: 5px 0;
} input {
width: 49%;
height: 45 px;
margin-right: 1%;
margin-bottom: 1%;
} #tipinfo {
font-size: 15px;
color: rgb(255,0,0);
font-style: italic;
height: auto;
}
</style>
<script type="text/javascript"> function javacalljs() {
document.getElementById("tipinfo").innerHTML =
"<br\>JAVA调用了JS的无参函数";
} function javacalljswith(arg) {
document.getElementById("tipinfo").innerHTML = (arg);
}
</script>
</head>
<body>
<header class="bar bar-nav">
<h1 class='title'>网页打印演示</h1>
</header>
<div class="content">
<div class="content-padded grid-demo"> <div id="tipinfo">打印机状态</div>
<div class="item-content">
<div class="item-media"><i class="icon icon-form-comment"></i></div>
<div class="item-inner">
<div class="item-title label">输入打印内容</div>
<div class="item-input">
<textarea id="inputtxt">打印内容测试,一维码生成请输入数字</textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-50">
<input type="button" class="button button-fill" value="生成二维码" onclick="window.android.createQRCode(document.getElementById('inputtxt').value)" />
</div>
<div class="col-50">
<input type="button" class="button button-fill" value="生成条码" onclick="window.android.createBarCode(document.getElementById('inputtxt').value)" />
</div>
</div>
<div class="row">
<div class="col-50">
<input type="button" class="button button-fill" value="打印文本" onclick="window.android.printText(document.getElementById('inputtxt').value)" />
</div>
<div class="col-50">
<input type="button" class="button button-fill" value="打印Unicode" onclick="window.android.printUnicode('hello, begin to smart print!')" />
</div>
</div>
<div class="row">
<div class="col-50">
<input type="button" class="button button-fill" value="选择图片" onclick="window.android.selectPic()" />
</div>
<div class="col-50">
<input type="button" class="button button-fill" value="打印图片" onclick="window.android.printPic()" />
</div>
</div>
<div class="row">
<div class="col-50">
<input type="button" class="button button-fill" value="打印网络图片" onclick="window.android.printNetPic()" />
</div>
<div class="col-50">
<input type="button" class="button button-fill" value="打印模板二" onclick="window.android.printStyleTwo()" />
</div>
</div>
<div class="row">
<div class="col-50">
<input type="button" class="button button-fill" value="打印模板一" onclick="window.android.printStyleOne()" />
</div>
<div class="col-50">
<input type="button" class="button button-fill" value="打印模板三" onclick="window.android.printStyleThree()" />
</div>
</div>
<div class="row">
<div class="col-50">
<input type="button" class="button button-fill" value="获取打印机状态" onclick="window.android.getPrintStatus()" />
</div>
</div>
</div>
</div>
</body>
</html>