Search code examples
androidandroid-wifiandroid-permissions

Performing network scan requiring permission for coarse location


I am working on an app which does a network scan and puts all the found SSIDs into a spinner.

Android Studio warns that you need permission for CHANGE_WIFI_STATE. Upon adding this into the manifest, Android Studio doesn't give any warning by the WifiManager.getScanResults() returns 0 networks. I've found that I need to add/request permission for ACCESS_COARSE_LOCATION.

All I need is the network SSID, I don't care where the user is located, so why do I/the user need to allow the location permission just to get a list of available networks. Below is how I am currently doing the scan:

    activity.registerReceiver(mWifiScannerReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
            wifiManager = (WifiManager)activity.getSystemService(Context.WIFI_SERVICE);

            wifiManager.startScan();

And my receiver:

if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION))
            {
                List<ScanResult> scanResults = wifiManager.getScanResults();
                wifiNetworkList.clear();
                //List<String> ssids = new ArrayList<>();
                for (int i = 0; i < scanResults.size(); i++)
                {
                    wifiNetworkList.add(scanResults.get(i).SSID);
                    //ssids.add(scanResults.get(i).SSID);
                }
                //wifiNetworkList = ssids;
                wifiAdapter.notifyDataSetChanged();
            }

Solution

  • I don't care where the user is located

    Yes, but given the network SSID, you can find out where the user is located, if the location of that WiFi network is known.

    why do I/the user need to allow the location permission just to get a list of available networks

    For improved user privacy, as of Android 6.0.