Skip to content Skip to sidebar Skip to footer

Android - List Wifi Access Points

I want to get list of wifi access points.Thank you very much.My code is below public static void backupWifi(Context context) { WifiManager wifiManager = (WifiManager) conte

Solution 1:

You need to create a BroadcastReceiver to listen for Wifi scan results:

private final BroadcastReceiver mWifiScanReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context c, Intent intent) {
        if (intent.getAction() == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) {
            List<ScanResult> mScanResults = wifi.getScanResults();
            // add your logic here
        }
    }
}

In onCreate() you would assign mWifiManager and initiate a scan:

mWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
mWifiManager.startScan();

This code which handles your scan results would run every time a new scan result is available, updating the result.


Solution 2:

First get a list of available wifi points-

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        List<ScanResult> apList = wifiManager.getScanResults();

apList - is the list of all available wifi points in the most recent scan.

You can set this apList to a ListView. NB:- this method returns only the recently scanned wifi points


Post a Comment for "Android - List Wifi Access Points"