Thanesh Davuluri
Thanesh Davuluri

Reputation: 21

Get List of Available WiFi networks without location services in Android

EDIT: I know that SCAN_RESULTS_AVAILABLE_ACTION returns a list of size '0' if location services are off.The question was how to do it without location services.

PREVIOUS: I need a list of all available WiFi networks to the phone,and use that list to populate a ListView in my app. I will later connect to the desired network from my app.

I have achieved the above by using ,

 wifiManager.startScan();

and I have registered a BroadcastReciever for receiving an intimation when a scan is complete like below,

registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));

receiver code is as follows,

 class WifiReceiver extends BroadcastReceiver {

        // This method call when number of wifiManager connections changed
        public void onReceive(Context c, Intent intent) {
            wifiResults.clear();
            wifiList = wifiManager.getScanResults();
            for(int i = 0; i < wifiList.size(); i++){
                if(!wifiList.get(i).SSID.equals(""))
                wifiResults.add(wifiList.get(i).SSID+" signal:"+wifiList.get(i).level);
            }
            adapter.notifyDataSetChanged();
            wifiRefreshLayout.setRefreshing(false);

        }
    }

the problem is I am having to enable location services every time I want the above information.I don't really see the point here as I don't need the location services here as other apps like "SHAREit" do the same without needing location services .Is there a better approach for achieving this?

Upvotes: 1

Views: 1236

Answers (1)

manas.abrol
manas.abrol

Reputation: 905

We can get the list of available WIFI without GPS turned on by setting the app's targetSDKversion to 21 or lower.

Upvotes: 2

Related Questions