android 蓝牙连接 关键类
BluetoothDevice--------------------蓝牙设备
BluetoothGattCallback--------------连接回调
BluetoothGatt----------------------gatt
1. public BluetoothGatt connectGatt(Context context, boolean autoConnect,
BluetoothGattCallback callback) ;
2.public BluetoothGatt connectGatt(Context context, boolean autoConnect,
BluetoothGattCallback callback, int transport) ;
3.public BluetoothGatt connect Gatt(Context context, boolean autoConnect,
BluetoothGattCallback callback, int transport, int phy) ;
4.public BluetoothGatt connectGatt(Context context, boolean autoConnect,
BluetoothGattCallback callback, int transport, int phy,
Handler handler) ;
5.public BluetoothGatt connectGatt(Context context, boolean autoConnect,
BluetoothGattCallback callback, int transport, boolean opportunistic, int phy, Handler handler) ; *
----autoConnect 是否自动连接参数。
----transport 是否低功耗。
-----phy。 物理层;
GATT协议简介
GATT(通用属性配置文件)是蓝牙技术中的一个关键协议,它规定了在蓝牙设备之间如何交换数据和通信。让我用通俗易懂的语言来解释一下:
想象你有一台手机和一个蓝牙耳机。现在,你想通过蓝牙耳机听音乐。为了实现这个目标,手机和蓝牙耳机之间需要进行通信。GATT就是控制这个通信的方式。
在GATT中,我们有两个角色:服务器和客户端。
-
服务器: 服务器实际上是你想要控制或者与之通信的设备,比如蓝牙耳机。它有一些可以被控制或者读取的属性,比如音量、电池状态等。
-
客户端: 客户端是控制服务器的设备,比如你的手机。它发