Android蓝牙开发(一):从源码看蓝牙

Android API27为例,先看下源码都要哪些类?

android.bluetooth包下有有一个le包(ble低功耗相关的类),和其他类
在这里插入图片描述
如图所示,核心类为

BluetoothAdapter (本地蓝牙适配器):使用这个你可以发现其他蓝牙设备,查询已配对的设备列表

BluetoothDevice (远程蓝牙设备):与远程设备的BluetoothSocket连接,或查询关于设备名称、地址、连接状态等设备信息。

BluetoothSocket(蓝牙socket的接口):与其他蓝牙设备通过InputStream和OutputStream交换数据。(和TCP Socket类似)

BluetoothServerSocket(开放的服务器socket):它监听接受的请求并接受连接(与TCP ServerSocket类似)

其他:

BluetoothHeadset
提供对移动手机使用的蓝牙耳机的支持。它包含了Headset and Hands-Free (v1.5)配置文件。

健康设备开发:Bluetooth HDP (Health Device Profile) ,蓝牙血压计,蓝牙体重秤开发

GATT(Generic Attribute Profile)协议:
现在低功耗蓝牙(BLE)连接都是建立在GATT协议之上,GATT是一个在蓝牙连接之上的发送和接收很短的数据段的通用规范,
这些很短的数据段被称为属性(Attribute)

基础代码案例:

蓝牙socket聊天
https://www.android-doc.com/resources/samples/BluetoothChat/index.html
https://github.com/MrXiong/BluetoothChat

API:
https://www.android-doc.com/guide/topics/connectivity/bluetooth.html

发布了55 篇原创文章 · 获赞 93 · 访问量 33万+

猜你喜欢

转载自blog.csdn.net/zx_android/article/details/95637834