1:蓝牙权限声明

2:获取蓝牙设备 BluetoothAdapter

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

if (mBluetoothAdapter == null && !mBluetoothAdapter.isEnabled()) {

Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

startActivityForResult(intent, REQUEST_ENABLE_BT);

}

3:获取虚拟蓝牙设备

String innerprinter_address = "00:11:22:33:44:55";

BluetoothDevice innerprinter_device = null;

Set devices = mBluetoothAdapter.getBondedDevices();

for(BluetoothDevice device : devices){

if(device.getAddress().equals(innerprinter_address)){

innerprinter_device = device;

}

}

4 : 获取蓝牙套接字 BluetoothSocket

UUID PRINTER_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")

BluetoothSocket mSocket = innerprinter_device.createRfcommSocketToServiceRecord(PRINTER_UUID);

5 : 打印订单

OutputStream mOut = mSocket.getOutputStream();

private void sendData(byte[] bytes) {

if (mOut != null) {

try {

mOut.write(bytes, 0, bytes.length);

mOut.flush();

} catch (IOException e) {

Log.e("TAG", e.getMessage());

} finally {

try {

mOut.close();

} catch (IOException e) { }

}

}

}

打印数据举例

public static final byte[] MEITUAN = { 0x1b, (byte) 0x40, (byte) 0x1b, (byte) 0x61, (byte) 0x01, (byte) 0x1d,

(byte) 0x21, (byte) 0x11, (byte) 0xa3, (byte) 0xa3, (byte) 0x31, (byte) 0x20, (byte) 0x20, (byte) 0xc3,

(byte) 0xc0, (byte) 0xcd, (byte) 0xc5, (byte) 0xb2, (byte) 0xe2, (byte) 0xca, (byte) 0xd4, (byte) 0x0a,

(byte) 0x0a, (byte) 0x1d, (byte) 0x21, (byte) 0x00, (byte) 0xd4, (byte) 0xc1, (byte) 0xcf, (byte) 0xe3,

(byte) 0xb8, (byte) 0xdb, (byte) 0xca, (byte) 0xbd, (byte) 0xc9, (byte) 0xd5, (byte) 0xc0, (byte) 0xb0,

(byte) 0x28, (byte) 0xb5, (byte) 0xda, (byte) 0x31, (byte) 0xc1, (byte) 0xaa, (byte) 0x29, (byte) 0x0a,

(byte) 0x1b, (byte) 0x21, (byte) 0x10, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x0a, (byte) 0x2a, (byte) 0x20, (byte) 0x2a, (byte) 0x20,

(byte) 0x2a, (byte) 0x20, (byte) 0x2a, (byte) 0x20, (byte) 0x2a, (byte) 0x20, (byte) 0x2a, (byte) 0x20,

(byte) 0x20, (byte) 0xd4, (byte) 0xa4, (byte) 0xb6, (byte) 0xa9, (byte) 0xb5, (byte) 0xa5, (byte) 0x20,

(byte) 0x20, (byte) 0x2a, (byte) 0x20, (byte) 0x2a, (byte) 0x20, (byte) 0x2a, (byte) 0x20, (byte) 0x2a,

(byte) 0x20, (byte) 0x2a, (byte) 0x20, (byte) 0x2a, (byte) 0x0a, (byte) 0xc6, (byte) 0xda, (byte) 0xcd,

(byte) 0xfb, (byte) 0xcb, (byte) 0xcd, (byte) 0xb4, (byte) 0xef, (byte) 0xca, (byte) 0xb1, (byte) 0xbc,

(byte) 0xe4, (byte) 0x3a, (byte) 0x20, (byte) 0x5b, (byte) 0x31, (byte) 0x38, (byte) 0x3a, (byte) 0x30,

(byte) 0x30, (byte) 0x5d, (byte) 0x0a, (byte) 0x1d, (byte) 0x21, (byte) 0x00, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x0a, (byte) 0x1b,

(byte) 0x61, (byte) 0x00, (byte) 0xcf, (byte) 0xc2, (byte) 0xb5, (byte) 0xa5, (byte) 0xca, (byte) 0xb1,

(byte) 0xbc, (byte) 0xe4, (byte) 0x3a, (byte) 0x30, (byte) 0x31, (byte) 0x2d, (byte) 0x30, (byte) 0x31,

(byte) 0x20, (byte) 0x31, (byte) 0x32, (byte) 0x3a, (byte) 0x30, (byte) 0x30, (byte) 0x0a, (byte) 0x1b,

(byte) 0x21, (byte) 0x10, (byte) 0xb1, (byte) 0xb8, (byte) 0xd7, (byte) 0xa2, (byte) 0x3a, (byte) 0xb1,

(byte) 0xf0, (byte) 0xcc, (byte) 0xab, (byte) 0xc0, (byte) 0xb1, (byte) 0x0a, (byte) 0x1d, (byte) 0x21,

(byte) 0x00, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x0a, (byte) 0xb2, (byte) 0xcb, (byte) 0xc3, (byte) 0xfb, (byte) 0x09, (byte) 0x09,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0xca, (byte) 0xfd, (byte) 0xc1, (byte) 0xbf, (byte) 0x09,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0xd0, (byte) 0xa1, (byte) 0xbc, (byte) 0xc6,

(byte) 0x09, (byte) 0x0a, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x0a, (byte) 0x1b, (byte) 0x21, (byte) 0x10, (byte) 0xba, (byte) 0xec,

(byte) 0xc9, (byte) 0xd5, (byte) 0xc8, (byte) 0xe2, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x78, (byte) 0x31, (byte) 0x09, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x31, (byte) 0x32, (byte) 0x0a, (byte) 0x1d,

(byte) 0x21, (byte) 0x00, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x0a, (byte) 0xc5, (byte) 0xe4, (byte) 0xcb, (byte) 0xcd, (byte) 0xb7,

(byte) 0xd1, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x35, (byte) 0x0a, (byte) 0xb2, (byte) 0xcd, (byte) 0xba, (byte) 0xd0,

(byte) 0xb7, (byte) 0xd1, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x31, (byte) 0x0a, (byte) 0x5b, (byte) 0xb3, (byte) 0xac,

(byte) 0xca, (byte) 0xb1, (byte) 0xc5, (byte) 0xe2, (byte) 0xb8, (byte) 0xb6, (byte) 0x5d, (byte) 0x20,

(byte) 0x2d, (byte) 0xcf, (byte) 0xea, (byte) 0xbc, (byte) 0xfb, (byte) 0xb6, (byte) 0xa9, (byte) 0xb5,

(byte) 0xa5, (byte) 0x0a, (byte) 0xbf, (byte) 0xc9, (byte) 0xbf, (byte) 0xda, (byte) 0xbf, (byte) 0xc9,

(byte) 0xc0, (byte) 0xd6, (byte) 0x3a, (byte) 0x78, (byte) 0x31, (byte) 0x0a, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x0a, (byte) 0x1b,

(byte) 0x21, (byte) 0x10, (byte) 0xba, (byte) 0xcf, (byte) 0xbc, (byte) 0xc6, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,

(byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x31, (byte) 0x38,

(byte) 0xd4, (byte) 0xaa, (byte) 0x0a, (byte) 0x1b, (byte) 0x40, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x0a, (byte) 0x1d, (byte) 0x21,

(byte) 0x11, (byte) 0xd5, (byte) 0xc5, (byte) 0x2a, (byte) 0x20, (byte) 0x31, (byte) 0x38, (byte) 0x33,

(byte) 0x31, (byte) 0x32, (byte) 0x33, (byte) 0x34, (byte) 0x35, (byte) 0x36, (byte) 0x37, (byte) 0x38,

(byte) 0x0a, (byte) 0xb5, (byte) 0xd8, (byte) 0xd6, (byte) 0xb7, (byte) 0xd0, (byte) 0xc5, (byte) 0xcf,

(byte) 0xa2, (byte) 0x0a, (byte) 0x1d, (byte) 0x21, (byte) 0x00, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d,

(byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x2d, (byte) 0x0a, (byte) 0x0a, (byte) 0x1b,

(byte) 0x40, (byte) 0x1b, (byte) 0x61, (byte) 0x01, (byte) 0x1d, (byte) 0x21, (byte) 0x11, (byte) 0xa3,

(byte) 0xa3, (byte) 0x31, (byte) 0x20, (byte) 0x20, (byte) 0xc3, (byte) 0xc0, (byte) 0xcd, (byte) 0xc5,

(byte) 0xb2, (byte) 0xe2, (byte) 0xca, (byte) 0xd4, (byte) 0x0a, (byte) 0x1d, (byte) 0x21, (byte) 0x00,

(byte) 0x1b, (byte) 0x40, (byte) 0x0a, (byte) 0x0a, (byte) 0x0a, (byte) 0x1d, (byte) 0x56, (byte) 0x00 };

android 打印机怎么拿到蓝牙地址,Android 商米蓝牙打印机的使用方式相关推荐

  1. android9获取蓝牙地址,Android获取本机蓝牙地址

    从Android6.0开始,通过BluetoothAdapter.getDefaultAdapter().getAddress()获取的地址是一个固定值02:00:00:00:00:00,部分从低版本 ...

  2. android go预览版下载地址,Android 11 Go正式版-Android 11 Go安卓正式版预约 v1.0.0-友情手机站...

    Android 11 Go正式版是谷歌最新发布的安卓系统,性能各方面都是有提升,给予每位用户最佳的使用体验,体验最佳的操作,安卓手机与苹果手机一样备受所有用户的喜欢,各种功能都有改进,提供给用户最强的 ...

  3. android studio gradle官网下载地址,Android Studio离线配置gradle(附gradle下载地址)

    导入新的android studio工程后经常由于多种缘由没法联网进行gradle下载,只能寻找离线手动配置gradle的方法,踩过很多坑后,最终经过如下几步android 解决:web 1. 下载与 ...

  4. android 调用相机并获取图片地址,Android 7.0使用FileProvider获取相机拍照的图片路径...

    这里主要是基于Android 7.0,Nougat 实现一个获取相机拍照的图片后,使用FileProvider把图片转换为实际的路径. 首先需要在AndroidManifest.xml声明调用相机的权 ...

  5. BLE学习(4):蓝牙地址类型和设备的隐私

    蓝牙地址也被称为蓝牙MAC地址,它能唯一标识一个蓝牙设备的48位的值.在蓝牙规范中,它被称为BD_ADDR.蓝牙的地址类型可以分为两种:public addresses和random addresse ...

  6. android 蓝牙地址连接打印机,android 连接蓝牙打印机 BluetoothAdapter

    android 连接蓝牙打印机 BluetoothAdapter 源码下载地址:https://github.com/yylxy/BluetoothText.git public class Prin ...

  7. android8.1获取蓝牙地址,[蓝牙] Android 8.1 获取蓝牙设备地址无效;02:00:00:00:00:00

    序言: 对于这个问题, 谷歌是这样说的: 为了向用户提供更好的数据保护,从此版本开始,Android删除了使用Wi-Fi和蓝牙API对应用程序的设备本地硬件标识符的编程访问. ok.至此我们已经知道为 ...

  8. Android获取本机蓝牙地址

    从Android6.0开始,通过BluetoothAdapter.getDefaultAdapter().getAddress()获取的地址是一个固定值02:00:00:00:00:00,部分从低版本 ...

  9. Zebra POS打印机Wifi无线打印方案和Android实现

    前段时间做了一个无线打印的Android App,打印机用的是Zebra的 QL 220(移动打印机)和GX 430t(桌面打印机).这里给大家分享一下具体实现方法.调用打印机用的是Zebra提供的Z ...

最新文章

  1. Message、Handler、Message Queue、Looper之间的关系
  2. 分布式服务跟踪及Spring Cloud的实现
  3. java多线程的同步
  4. DataTable的Compute方法和Expression语法
  5. hdu 1723 DP/递推
  6. C++类、函数、指针
  7. 【Hibernate】Hibernate的jar包的用途
  8. 怎么设置电脑屏幕一直亮着_电脑屏幕缩小了肿么调回去。分辨率调了没用。
  9. 我想solo自己一个人!
  10. CBOW模型的学习、Trainer类的实现
  11. proe50安装方法64位_proe5.0安装方法64位
  12. 2011 - 12 - 12记录2011 - 12 - 11
  13. 复制assert目录文件到私有目录_在电脑上复制目录的方法
  14. RHEL7及CentOS7的语言、字符编码、键盘映射、X11布局设置(localectl)-系统管理(1)...
  15. java实现栈的方法
  16. ansys中ex是什么意思_ansys命令流mp,ex
  17. ExtJs6学习(一)【ExtJs介绍】
  18. 基于搜狗平台的微信文章爬虫
  19. Tedddby Activator V5.1,免费绕过iOS 14.7Beta,支持iCloud登录
  20. 课程理论知识、教学实施

热门文章

  1. vlookup使用步骤_vlookup怎么用详细步骤(vlookup函数的使用方法是什么)
  2. 【Chaos Mesh官方文档】Chaosd Introduction
  3. websocket和socket.io
  4. 目标检测 从古典走进R-CNN
  5. 有没有html代码听力的软件吗,听力软件VoScreen,值得介绍一下
  6. 什么CRM客户管理系统好用?公司规模不大,有推荐吗
  7. html table标签
  8. 00——Phsical Design初稿2021-09-06上午
  9. 你真的懂面形误差PV和RMS的计算方法吗?均方根(RMS)与方差、标准差有什么区别?Zemax中的波前RMS是什么?(光学测量、光学设计必看)
  10. bmp文件格式详细解析(转载)