Android蓝牙4.0API接口之BluetoothAdapter.LeScanCallback

android.bluetooth

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.

//Android4.3即API18支持蓝牙4.0

蓝牙API中的接口

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

使用到这个回调的两个方法(查找周围设备的方法)

其中方法2的详细解释:

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

这个方法在API21中被替换至下方法。

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

该方法的返回值类型为TRUE或者FALSe

关于这个方法,是一个抽象的方法

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.


  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值