我正在尝试扫描WiFi并获取结果,但是问题是当我使用“ WifiManager.getScanResult()”时,它仅显示空值
代码
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
@ReactMethod
public void loadWifiList(Callback successCallback, Callback errorCallback) {
try {
Log.e(TAG, "----Attempt try----");
List<ScanResult> results = wifi.getScanResults();
JSONArray wifiArray = new JSONArray();
Log.e(TAG, "-----results:---- " + results);
for (ScanResult result : results) {
Log.e(TAG, "SSID : " + result.SSID);
JSONObject wifiObject = new JSONObject();
if (!result.SSID.equals("")) {
try {
wifiObject.put("SSID", result.SSID);
wifiObject.put("BSSID", result.BSSID);
wifiObject.put("capabilities", result.capabilities);
wifiObject.put("frequency", result.frequency);
wifiObject.put("level", result.level);
wifiObject.put("timestamp", result.timestamp);
//Other fields not added
//wifiObject.put("operatorFriendlyName", result.operatorFriendlyName);
//wifiObject.put("venueName", result.venueName);
//wifiObject.put("centerFreq0", result.centerFreq0);
//wifiObject.put("centerFreq1", result.centerFreq1);
//wifiObject.put("channelWidth", result.channelWidth);
} catch (Exceptional e) {
errorCallback.invoke(e.getMessage());
}
wifiArray.put(wifiObject);
}
}
successCallback.invoke(wifiArray.toString());
} catch (IllegalViewOperationException e) {
errorCallback.invoke(e.getMessage());
}
}
反应代码
detectedWifiNetwork(){
wifi.loadWifiList((wifiStringList) => {
var wifiArray = JSON.parse(wifiStringList);
alert("WifiList:"+wifiArray)
},
(error) => {
alert(error)
}
);
}
任何人,请给我解决问题的方法。谢谢!