Provides classes that manage Bluetooth functionality, such as scanning for devices, connecting with devices, and managing data transfer between devices. The Bluetooth API supports both "Classic Bluetooth" and Bluetooth Low Energy.

For more information about Classic Bluetooth, see the Bluetooth guide. For more information about Bluetooth Low Energy, see the Bluetooth Low Energy (BLE) guide.

The Bluetooth APIs let applications:

  • Scan for other Bluetooth devices (including BLE devices).
  • //扫描其他的蓝牙设备包括使用BLE的蓝牙设备
  • Query the local Bluetooth adapter for paired Bluetooth devices.
  • //查询本地的蓝牙适配器以判断设备是否适合
  • Establish RFCOMM channels/sockets.
  • //建立串行通道或者socket
  • Connect to specified sockets on other devices.
  • 可以使用指定的协议与其他设备链接
  • Transfer data to and from other devices.
  • //实现数据的传输和处理
  • Communicate with BLE devices, such as proximity sensors, heart rate monitors, fitness devices, and so on.
  • //与其他BLE设备进行通信,包括血压仪等等
  • Act as a GATT client or a GATT server (BLE).
  • //可以作为GATT的客户端和服务端

To perform Bluetooth communication using these APIs, an application must declare the BLUETOOTH permission. Some additional functionality, such as requesting device discovery, also requires the BLUETOOTH_ADMIN permission.


Note: Not all Android-powered devices provide Bluetooth functionality.



BluetoothAdapter.LeScanCallback  这个回调用以展示蓝牙扫描后的结果



This method was deprecated in API level 21.
use startScan(List, ScanSettings, ScanCallback) instead.


Starts a scan for Bluetooth LE devices, looking for devices that advertise given services.

Devices which advertise all specified services are reported using the onLeScan(BluetoothDevice, int, byte[]) callback.

Requires BLUETOOTH_ADMIN permission.


serviceUuids UUID: Array of services to look for目标设备

callback :BluetoothAdapter.LeScanCallback: the callback LE scan results are delivered



onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)

Callback reporting an LE device found during a device scan initiated发现 by the startLeScan(BluetoothAdapter.LeScanCallback) function.

public abstract void onLeScan (BluetoothDevice device, int rssi, byte[] scanRecord)

Callback reporting an LE device found during a device scan initiated by the startLeScan(BluetoothAdapter.LeScanCallback) function.

device  BluetoothDevice: Identifies the remote device

rssi int: The RSSI value for the remote device as reported by the Bluetooth hardware. 0 if no RSSI value is available.

scanRecord byte: The content内容 of the advertisement record 记录offered by the remote device.