赞
踩
由于自己工作原因,涉及到热敏打印机开发,因此自己写了一套热敏打印机SDK,目前暂时只支持蓝牙打印
我生成了jar包的形式,方便大家使用。里面代码的实现原理现在暂无时间去讲解,主要以如何使用为主。
SDK
源码地址
链接:https://github.com/875831461/ThomasPrinter
注意事项
目前只适配了蓝牙打印机,58型号80型号的均可以打印
已完成功能
扫描蓝牙
打印一行,打印一行两列,打印图片,打印条形码,二维码(需要打印机支持),倒置打印等。。
未完成功能
标签打印
如何导入jar包我就不说了。权限
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if((checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) ){
String[] permission = new String[]{
Manifest.permission.ACCESS_FINE_LOCATION
};
requestPermissions(permission, 11);
}
}
ThomasPrinterManage.getInstance().registerOnThomasPrinterChangeListener()
ThomasPrinterManage.getInstance().unregisterOnThomasPrinterChangeListener()
1.这种可以在打印机掉线时,如果打印机再次开机会自动连接,但是有时候会有问题
ThomasPrinterManage.getInstance().connectBluetoothDevice(this,address);
2.推荐使用这种方式连接打印机
ThomasPrinterManage.getInstance().connectBluetoothDevice(address);
Vector<Byte> data = new Vector<>(); ThermalPrinter thermalPrinter = new ThermalPrinter(); thermalPrinter.setCommand(data); thermalPrinter.initPrint(); // according to your paper size thermalPrinter.setPageSizeEighty(); //thermalPrinter.setPageSizeFiftyEight(); thermalPrinter.setWhiteOnBlack(); thermalPrinter.setAlignment(Alignment.CENTER); thermalPrinter.setFontSize(FontSize.LARGER); thermalPrinter.setText(getTextByte("White On Black")); thermalPrinter.cancelWhiteOnBlack(); thermalPrinter.printAndFeedLine(); thermalPrinter.putText(getTextByte("content"), FontSize.NORMAL, Alignment.CENTER,false); thermalPrinter.printAndFeedLine(); thermalPrinter.putText(getTextByte("content"), FontSize.NORMAL, Alignment.RIGHT,true); thermalPrinter.printAndFeedLine(); thermalPrinter.putText(getTextByte("content"), FontSize.BIG, Alignment.RIGHT,false); thermalPrinter.printAndFeedLine(); thermalPrinter.putText(getTextByte("content"), FontSize.LARGER, Alignment.LEFT,false); thermalPrinter.printAndFeedLine(); thermalPrinter.setUnderline(true); thermalPrinter.setText(getTextByte("content")); thermalPrinter.setUnderline(false); thermalPrinter.printAndFeedLine(); thermalPrinter.putTextColumn(getTextByte("column one"), getTextByte("column two"),FontSize.NORMAL); thermalPrinter.putTextColumn(getTextByte("column one"), getTextByte("column two"),FontSize.NORMAL); thermalPrinter.putTextColumn(getTextByte("column one"), getTextByte("column two"),FontSize.BIG); thermalPrinter.putTextColumn(getTextByte("column one"), getTextByte("column two"),FontSize.NORMAL); // not useful for XML images Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.smart); thermalPrinter.putBitmap(bitmap); thermalPrinter.printBarCode("12345684",Alignment.CENTER,3,80); // this need printer support thermalPrinter.printQrCode(Alignment.CENTER,3,48,"thomas printer"); thermalPrinter.setCutPaper(); // if you connect more than one devices you can use this method ThomasPrinterManage.getInstance().writeSendDataAllDevice(data);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。