通过此示例和gps禁用,我没有获得ScanResults。启用gps后我会得到结果。(在Android 7上测试)我必须启用gps是正常的吗?有没有办法在没有GPS的情况下获得所有wifi的BSSID?
public void readWifis(Activity activity) {
// Get the wifi manager.
// Provides the primary API for managing all aspects of Wi-Fi connectivity.
WifiManager wifiManager = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
activity.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context c, Intent intent) {
List<ScanResult> results = wifiManager.getScanResults();
for (ScanResult ap : results) {
Log.d("myTag", "SSID=" + ap.SSID + " MAC=" + ap.BSSID);
}
}
},
// An access point scan has completed, and results are available from the supplicant. Call getScanResults() to obtain the results.
new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
// Request a scan for access points.
wifiManager.startScan();
}
答案 0 :(得分:0)
不是必须启用GPS,而是根据请求的位置使用GPS,Wi-Fi或移动网络的定位服务。
BSSID和SSID的问题在于,它们被视为位置信息,因此不仅需要用户(自Android 8.1起)授予位置许可,还需要启用位置服务。