Android蓝牙打印机例子
上一篇是佳博网络打印机的,这一篇是关于蓝牙(不是低功耗4.0)打印机的例子。
/*** 检查是否有纸指令*/public static final byte[] stateBype = new byte[] { 0x10, 0x04, 0x04 };/*** 检查是否有纸指令*/
// public static final byte[] stateBype2 = new byte[] { 0x1B, 0x76 };/*** 居左对齐*/public static final Byte[] toLeft = new Byte[] { 0x1B, 0x61, 0x00 };/*** 居中对齐*/public static final Byte[] toCenter = new Byte[] { 0x1B, 0x61, 0x01 };/*** 加大2倍*/public static final Byte[] toLarge = new Byte[] { 0x1D, 0x21, 0x11 };/*** 取消加大*/public static final Byte[] cancleLarge = new Byte[] { 0x1D, 0x21, 0x00 };/*** 加粗*/public static final Byte[] toLarge2 = new Byte[] { 0x1B, 0x45, 0x01 };/*** 取消加粗*/public static final Byte[] cancleLarge2 = new Byte[] { 0x1B, 0x45, 0x00 };/*** 加载走纸命令*/public static final Byte[] cut = new Byte[] { 0x1D, 0x56, 0x42, 0x00 };// 切纸并且走纸/*** 设置模型*/public static final Byte[] setCodeModel = new Byte[] { 0x1D, 0x28, 0x6B, 0x04, 0x00, 0x31, 0x41, 0x32, 0x00 };/*** 设置单元格大小*/public static final Byte[] setCodeSize = new Byte[] { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x43, 0x09 };/*** 设置纠错正等级*/public static final Byte[] setCodeLevel = new Byte[] { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x45, 0x30 };/*** 加载二维码*/public static Byte[] setCode = new Byte[8];/*** 打印二维码*/public static final Byte[] printCode = new Byte[] { 0x1D, 0x28, 0x6B, 0x03, 0x00, 0x31, 0x51, 0x30 };/*** 设置加载二维码指令* @param code*/public static void doSetCode(String code) {Common.showDeBug((byte) code.length());setCode[0] = 0x1D;setCode[1] = 0x28;setCode[2] = 0x6B;setCode[3] = (byte) (code.length()+3);setCode[4] = 0x00;setCode[5] = 0x31;setCode[6] = 0x50;setCode[7] = 0x30;}/*** 合并两个byte数组* * @param byte_1* @param byte_2* @return*/public static byte[] byteMerger(byte[] byte_1, byte[] byte_2) {byte[] byte_3 = new byte[byte_1.length+byte_2.length];System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);return byte_3;}/*** int[]转byte[]* @param arg* @return*/public static byte[] intTobyte(int arg[]) {byte[] byteTmp = new byte[arg.length];for (int i = 0; i < arg.length; i++) {byteTmp[i] = (byte)arg[i];}return byteTmp;}/*** byte转Byte* * @param srcArray* @param cpyArray*/public static void CopyArray(byte[] srcArray, Byte[] cpyArray) {for (int index = 0; index < cpyArray.length; index++) {cpyArray[index] = srcArray[index];}}/*** List<Byte>转换为byte[]* @param ByteArray* @return*/public static byte[] convertFromListByteArrayTobyteArray(List<Byte> ByteArray) {byte[] byteArray = new byte[ByteArray.size()];for (int index = 0; index < byteArray.length; index++) {byteArray[index] = ByteArray.get(index);}return byteArray;}/*** 去重复* @param li* @return*/public static List<String> removeDuplicateWithOrder(List<String> li) {List<String> list = new ArrayList<String>();for(int i=0; i<li.size(); i++){String str = li.get(i); //获取传入集合对象的每一个元素if(!list.contains(str)){ //查看新集合中是否有指定的元素,如果没有则加入list.add(str);}}return list; //返回集合}
检查打印机纸的状态:
/*** 佳博蓝牙打印机,检查纸的状态:* 当接收状态为18时,表示蓝牙打印机是正常状态;接收状态为114(无纸)或114(没关盖)时,表示不正常状态*/public int doCheckJiaboPaperState() {/**1:正常,0:异常,-1:链接失败*/int flag = 0;try {InputStream bis = bluetoothSocket.getInputStream(); outputStream.write(BlueThPrintInfo.stateBype);outputStream.flush();int tmp = bis.read();if (tmp == 18) {flag = 1;} else {flag = 0;}} catch (Exception e) {flag = -1;e.printStackTrace();}return flag;}
剩下的步骤和上一篇Android网络打印机一样。这里就不一一说明了。
Android蓝牙打印机例子相关推荐
- android 蓝牙打印机(ESC/POS 热敏打印机),打印菜单小票和图片,对蓝牙配对和连接打印功能进行了封装,让你超快实现蓝牙打印功能
BluetoothPrint 项目地址:liuGuiRong18/BluetoothPrint 简介:android 蓝牙打印机(ESC/POS 热敏打印机),打印菜单小票和图片,对蓝牙配对和连接打 ...
- 蓝牙打印 设置打印样式_GitHub - shen173869710/PrintUtils: Android蓝牙打印机,带你真正了解各种打印格式。...
PrintUtils Android蓝牙打印机,带你真正了解各种打印格式. 效果图如下: 具体用法是: (1)手机通过蓝牙连接打印机 (2)从BluetoothSocket中getOutputStre ...
- android蓝牙打印机
您还未登录!|登录|注册|帮助 首页 业界 移动 云计算 研发 论坛 博客 下载 更多 reality_jie的专栏 编程的过程是一种微妙的享受 目录视图 摘要视图 订阅 CSDN2013年度博客之星 ...
- Android 蓝牙打印机格式问题
在项目开发中要用Android手机连接蓝牙打印机,但是数据一直无法上下对齐,在网上各种百度之后,找到了一个方法. 因为我们用的蓝牙打印机编码格式是GBK,所以在向打印机发送消息的时候,要str.get ...
- Android蓝牙打印机,带你真正了解各种打印格式
本文主要讲解蓝牙打印机在打印小票的过程中,如何打印各种常见格式.由于之前需要调试打印格式,但是苦于网上没有详细的讲解教程,无奈只能自给自足,自己封装了一个.如果各位盆友正在或者曾经苦恼蓝牙打印机的打印 ...
- Android蓝牙打印机功能开发完整Demo
蓝牙便携式打印机的种类繁多,支持的打印格式也不尽相同.按照指令集可划分为:ESC指令集.CPCL指令集,实现原理基本相同,我这里以佳博便携式打印机为例,进行蓝牙搜索配对并发送打印数据. 完整代码地址在 ...
- android 蓝牙打印机
最近在做一个安卓应用,其中有一个需求是要求用蓝牙连接打印机实现打印功能.一开始没有一点头绪,网上找了很多资料也找不到有用的数据.所以自己就去研究,最终,功夫不负有心人,顺利的完成了这个功能.下边贴出我 ...
- android蓝牙打印机打印图片,如何使用打印机(通过蓝牙打印)从Android设备打印图像和一些数据?...
尝试使用这个-. public class BluetoothPrinterActivity extends Activity { BluetoothAdapter mBTAdapter; Bluet ...
- Android蓝牙打印小票,仿美团外卖小票打印
这个一个Android蓝牙打印小票demo,类似美团外卖小票打印 自适应排版小票格式,一行两列和三列轻松搞定,文本长短不用愁 先看一下效果图: demo里主要是使用汉印打印机进行蓝牙小票打印,它还支持 ...
最新文章
- HttpClien GetPost
- 利用https实现站点访问
- LiveVideoStack线上分享第三季(二):对话机器人与儿童电子消费品
- python怎么用matplotlib画,用matplotlib在python中绘制OHLC图
- 2016陕西省省赛 ACM Rui and her functions B 二分
- C++中派生类隐式调用与显式调用基类的构造函数
- Ubuntu 下配置lamp环境
- Skip-Thought Vector —— 跳跃思维句表示
- 传统红色纹样图案背景|中式海报必备素材
- Conda activate报错 CommandNotFoundError: Your shell has not been properly configured to use ‘conda
- python自动化办公-用 Python 自动化办公能做到哪些有趣或有用的事情?
- 字节跳动面试经验 php,双指针算法:字节跳动初级面试题 PHP
- 让 Windows 的 R 用上 CUDA
- MySQL内核月报 2014.11-MySQL· 5.7改进·Recovery改进
- 预科计算机考试试题,少数民族预科计算机应用基础课程机考试题库的
- 软考(22)-网络存储、网络安全、网络规划与设计
- git拉代码错误Can't update:no tracked branch
- 鸿蒙系统不可能有了,【图片】华为鸿蒙系统的厉害之处在于 你可能非用不可
!【手机吧】_百度贴吧...
- 万字长文 | 数据分析师的机遇与挑战
- yt-dlp教程如何下载高清视频