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
......
上述代碼中紅色加粗的代碼即使是否運行搜索的限制條件。而紅色加藍部分為搜索設備的方法。因此我們將紅色加粗的部分進行凝視。該問題得到解決。