高通平台 android7.1 蓝牙的可见性设置

1、情景

本机设备只打开蓝牙开关,但不停留在设置里面蓝牙页面时,其他设备扫描不到本机设备。

2、Android7.1中,默认的行为是,只有在设置里面的蓝牙页面,才会开启蓝牙的可见性;如果只是打开下拉栏的蓝牙快捷开关,是不会开启蓝牙可见性的。

3、需求:

(1)打开蓝牙时,直接打开蓝牙可见性

(2)不停留在设置里面蓝牙页面时,要扫描到本机设备

4、需求一的解决方案:

打开蓝牙时,直接打开蓝牙可见性。如下:

路径:****/packages/apps/Bluetooth/src/com/android/bluetooth/btservice/AdapterProperties.java

复制代码
void onBluetoothReady() {
        Log.d(TAG, "ScanMode =  " + mScanMode );
        Log.d(TAG, "State =  " + getState() );

        // When BT is being turned on, all adapter properties will be sent in 1
        // callback. At this stage, set the scan mode.
        synchronized (mObject) {
            if (getState() == BluetoothAdapter.STATE_TURNING_ON &&
                    mScanMode == BluetoothAdapter.SCAN_MODE_NONE) {
                    /* mDiscoverableTimeout is part of the
                       adapterPropertyChangedCallback received before
                       onBluetoothReady */
                    if (mDiscoverableTimeout != 0)
					  //setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE);
                      setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
                    else /* if timeout == never (0) at startup */
                      setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
                    /* though not always required, this keeps NV up-to date on first-boot after flash */
                    setDiscoverableTimeout(mDiscoverableTimeout);
            }
        }
    }

如上图: 将 setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE); 改为

setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);即可。

5、需求二的解决方案,如下:

路径:******/packages/apps/Settings/src/com/android/settings/bluetooth/BluetoothSettings.java

复制代码
@Override
    public void onPause() {
        super.onPause();
        if (mBluetoothEnabler != null) {
            mBluetoothEnabler.pause();
        }

        // Make the device only visible to connected devices.
        //mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);

        if (isUiRestricted()) {
            return;
        }

        getActivity().unregisterReceiver(mReceiver);
    }

如上图,在onPause()方法中将mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);注释掉即可。

相关推荐
平头哥AI14 小时前
Day 22 _ 包装错误别丢链_%w、errors.Is 与 errors.As
android·服务器·学习·golang·go
聚美智数15 小时前
图片广告检测-图片审核-图片广告识别-图像广告检测
android
早睡早起身体好12317 小时前
用 XGrammar 约束大模型工具调用:解决参数为空的问题
android·人工智能·神经网络·机器学习·自然语言处理·vllm
大佐不会说日语~19 小时前
Android 16 下 uni-app APP 提示“网络连接失败”的排障与修复
android·uni-app
2501_9151063220 小时前
苹果App Store上架费用及流程全面解析
android·ios·小程序·https·uni-app·iphone·webview
YF02111 天前
Android 16系统App开机自启动方案
android
hm宋1 天前
安卓手机卡顿优化 —— 背景与使用指南
android
OxYGC1 天前
[Android] [WatchOS]智能手表第一篇: 实用工具与应用推荐
android·智能手表
嘟哩DuliDuli1 天前
创作 Agent 的任务状态该如何保存
android·java·javascript