android 9 让蓝牙开启 即可被发现

本文档介绍了如何在蓝牙适配器准备好时修改代码,以实现设备在打开蓝牙开关时即可被其他设备发现。默认情况下,设备仅能连接但不可被发现。通过修改btservice/AdapterProperties.java文件,将扫描模式设置为`BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE`,设备即可在连接状态下同时被发现。这涉及到了蓝牙连接和设备发现的配置细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

默认打开蓝牙开关 蓝牙是不可以被其他设备发现的

只能在蓝牙界面才可以被发现

如果想打开开关就被发现

需修改代码

btservice/AdapterProperties.java

 void onBluetoothReady() {
        debugLog("onBluetoothReady, state=" + BluetoothAdapter.nameForState(getState())
                + ", ScanMode=" + mScanMode);

        synchronized (mObject) {
            // Reset adapter and profile connection states
            setConnectionState(BluetoothAdapter.STATE_DISCONNECTED);
            mProfileConnectionState.clear();
            mProfilesConnected = 0;
            mProfilesConnecting = 0;
            mProfilesDisconnecting = 0;
            // adapterPropertyChangedCallback has already been received.  Set the scan mode.
            //setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE);

            //可以连接 不能被发现
            setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);

            //可以连接 也可以被发现
            
            // This keeps NV up-to date on first-boot after flash.
            setDiscoverableTimeout(mDiscoverableTimeout);
        }
    }

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值