Android 提供管理藍牙功能的類,例如掃描設備、連接設備以及管理設備之間的數據傳輸。Android 藍牙 API 支持 Classic Bluetooth(經典藍牙)和 Bluetooth Low Energy / BLE(低功耗藍牙)。在 Android 開發中,Android 的 Bluetooth Class 非常多,所以要小心使用。
Android Bluetooth 架構 Architecture |
Andoid 通用藍牙架構 |
- Applications–Android 藍牙應用程式,就是使用藍牙的 API 的程式
- Framework–提供給應用使用的 API,平時使用的 BluetoothAdapter,BluetoothDevice,BluetoothSocket 等
- Bluetooth Service–即 Bluetooth APP(Bluetooth.apk)也是屬於 java framework 範疇,不過由於它比較特殊,所以獨立出來,提供所有的上層服務以及與 Bluedroid 底層進行交互。其中 btAdapter 主要提供藍牙的基本操作,比如 enable、disable、discovery、pair、unpair、createRfcomm 等,其他的就都是 Profile 的各自的 Service
- Bluedroid–藍牙協議棧,提供所有藍牙的實際操作,開關藍牙,藍牙的管理,搜索管理,鏈路管理,各種 profile 的實現,包括 HCI,ACL,SCO,L2CAP,各種 profile 等
Bluetooth Classes 應用程序接口:
Class 屬性 |
描述 |
BluetoothA2dp |
This class provides the public APIs to control the Bluetooth A2DP profile。 |
BluetoothAdapter |
Represents the local device Bluetooth adapter。 |
BluetoothAssignedNumbers |
Bluetooth Assigned Numbers。 |
BluetoothClass |
Represents a Bluetooth class,which describes general characteristics and capabilities of a device。 |
BluetoothClass.Device |
Defines all device class constants。 |
BluetoothClass.Device.Major |
Defines all major device class constants。 |
BluetoothClass.Service |
Defines all service class constants。 |
BluetoothDevice |
Represents a remote Bluetooth device。 |
BluetoothGatt |
Public API for the Bluetooth GATT Profile。 |
BluetoothGattCallback |
This abstract class is used to implement BluetoothGatt callbacks。 |
BluetoothGattCharacteristic |
Represents a Bluetooth GATT Characteristic A GATT characteristic is a basic data element used to construct a GATT service,BluetoothGattService。 |
BluetoothGattDescriptor |
Represents a Bluetooth GATT Descriptor GATT Descriptors contain additional information and attributes of a GATT characteristic,BluetoothGattCharacteristic。 |
BluetoothGattServer |
Public API for the Bluetooth GATT Profile server role。 |
BluetoothGattServerCallback |
This abstract class is used to implement BluetoothGattServer callbacks。 |
BluetoothGattService |
Represents a Bluetooth GATT Service Gatt Service contains a collection of BluetoothGattCharacteristic,as well as referenced services。 |
BluetoothHeadset |
Public API for controlling the Bluetooth Headset Service。 |
BluetoothHealth |
This class was deprecated in API level 29。Health Device Profile (HDP) and MCAP protocol are no longer used。New apps should use Bluetooth Low Energy based solutions such as BluetoothGatt,BluetoothAdapter#listenUsingL2capChannel(),or BluetoothDevice#createL2capChannel(int) |
BluetoothHealthAppConfiguration |
This class was deprecated in API level 29。Health Device Profile (HDP) and MCAP protocol are no longer used。New apps should use Bluetooth Low Energy based solutions such as BluetoothGatt,BluetoothAdapter#listenUsingL2capChannel(),or BluetoothDevice#createL2capChannel(int) |
BluetoothHealthCallback |
This class was deprecated in API level 29。Health Device Profile (HDP) and MCAP protocol are no longer used。New apps should use Bluetooth Low Energy based solutions such as BluetoothGatt,BluetoothAdapter#listenUsingL2capChannel(),or BluetoothDevice#createL2capChannel(int) |
BluetoothHearingAid |
This class provides the public APIs to control the Hearing Aid profile。 |
BluetoothHidDevice |
Provides the public APIs to control the Bluetooth HID Device profile。 |
BluetoothHidDevice.Callback |
The template class that applications use to call callback functions on events from the HID host。 |
BluetoothHidDeviceAppQosSettings |
Represents the Quality of Service (QoS) settings for a Bluetooth HID Device application。 |
BluetoothHidDeviceAppSdpSettings |
Represents the Service Discovery Protocol (SDP) settings for a Bluetooth HID Device application。 |
BluetoothLeAudio |
This class provides the public APIs to control the LeAudio profile。 |
BluetoothManager |
High level manager used to obtain an instance of an BluetoothAdapter and to conduct overall Bluetooth Management。 |
BluetoothServerSocket |
A listening Bluetooth socket。 |
BluetoothSocket |
A connected or connecting Bluetooth socket。 |
BluetoothStatusCodes |
A class with constants representing possible return values for Bluetooth APIs。 |
Android 經典的藍牙代碼架構圖(Google 官方提供) |
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { // Device does not support Bluetooth } |
參考網址:
※ Bluetooth Overview
沒有留言:
張貼留言