0

Iam trying to scan WiFi and get the results, but the problem is when i using "WifiManager.getScanResult()"it showing only null value

Code

@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());
    }
}

react Code

detectedWifiNetwork(){
            wifi.loadWifiList((wifiStringList) => {
            var wifiArray = JSON.parse(wifiStringList);
            alert("WifiList:"+wifiArray)
            },
            (error) => {
            alert(error)
            }
            );  
            }

Anyone Please give me solution for the problem.thanks in advance

0 Answers0