默认打开蓝牙开关 蓝牙是不可以被其他设备发现的
只能在蓝牙界面才可以被发现
如果想打开开关就被发现
需修改代码
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);
}
}
本文档介绍了如何在蓝牙适配器准备好时修改代码,以实现设备在打开蓝牙开关时即可被其他设备发现。默认情况下,设备仅能连接但不可被发现。通过修改btservice/AdapterProperties.java文件,将扫描模式设置为`BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE`,设备即可在连接状态下同时被发现。这涉及到了蓝牙连接和设备发现的配置细节。
2589





