Android BLE蓝牙——客户端源码分析(十五)

        之前的两篇文章都是参考大佬的博客完成了应用层客户端与服务端的开发,下面我们按照之前的流程对源码进行分析。

1、权限声明

        这部分并不是本篇文章内容的重点,这里就不做分析了。

2、打开蓝牙

        这里使用过 action 去启动蓝牙,《Android 蓝牙开发——基础开发(三)》中已经分析过蓝牙的流程,虽然方式不同,但此处也不在做详细分析。

3、搜索设备

1、获取 BluetoothLeScanner 实体类 btLeScanner

2、调用 btLeScanner.startScan() 开始扫描

3、延时调用 btLeScanner.stopScan() 停止扫描

4、处理回调

BluetoothAdapter.getBluetoothLeScanner()

public BluetoothLeScanner getBluetoothLeScanner() {
    if (!getLeAccess()) {
        return null;
    }
    synchronized (mLock) {
        if (mBluetoothLeScanner == null) {
            mBluetoothLeScanner = new BluetoothLeScanner(this);
        }
        return mBluetoothLeScanner;

猜你喜欢

转载自blog.csdn.net/c19344881x/article/details/128797686