具体代码参考GitHub项目 点击跳转到GitHub项目地址:BluetoothConnectSample
蓝牙设备开发步奏
1、获取蓝牙开发相关权限
2、判断是否开启设备蓝牙功能,未开启跳转到开启页面
3、注册蓝牙设备广播监听
4、开始搜索蓝牙设备
5、连接蓝牙设备,拿到设备的输入和输出流
6、双方通讯,通过制定的协议发送和接收相关指令
7、通讯完成,主动断开与设备的连接
1、获取蓝牙开发相关权限
注册以下权限

获取相关权限

2、判断是否开启设备蓝牙功能,未开启跳转到开启页面

3、注册蓝牙设备广播监听
BluetoothDiscovery 实现 LifecycleObserver 接口绑定到 BtConnectActivity 的 LifeCycle 中管理生命周期,在 onCreate 中注册广播,在 onDestroy 中取消广播注册


4、开始搜索蓝牙设备

5、连接蓝牙设备,拿到设备的输入和输出流



6、Printer 双方通讯,通过制定的协议发送和接收相关指令


7、通讯完成,主动断开与设备的连接

具体代码参考GitHub项目 点击跳转到GitHub项目地址:BluetoothConnectSample
网友评论