https://blog.csdn.net/huangyabin001/article/details/36027575
【预期结果】:打开蓝牙。应该会自己主动搜索设备
依据重复測试发现。当蓝牙状态打开,而且有可用的设备的时候,或者存在已经配对成功的设备的时候。系统将不会在进行设备搜索,因此依据String定位到蓝牙的设置界面的Fragment为:BluetoothSettings.java.
在BluetoothSettings类的updateContent()方法中我们发现以下代码:
......
??????????????? //if (numberOfPairedDevices == 0) {
??????????????????? //preferenceScreen.removePreference(mPairedDevicesCategory);
??????????????????? if (scanState == true) {
??????????????????????? mActivityStarted = false;
??????????????????????? startScanning();
??????????????????? } else {
??????????????????????? if (!mAvailableDevicesCategoryIsPresent) {
??????????????????????????? getPreferenceScreen().addPreference(mAvailableDevicesCategory);
??????????????????????? }
??????????????????? }
??????????????? //}
??????????????? getActivity().invalidateOptionsMenu();
??????????????? return; // not break
......
上述代码中红色加粗的代码即使是否运行搜索的限制条件。而红色加蓝部分为搜索设备的方法。因此我们将红色加粗的部分进行凝视。该问题得到解决。
原文:https://www.cnblogs.com/xfgnongmin/p/10853833.html