0

Good afternoon. For a very long time I have been trying to get a list of wi-fi networks using WifiManager. When I try to get through a virtual device, I get only one fictional network with an SSID: Android Wifi. However, I do not receive networks from my real environment. When using a real device, it is not possible to get any network. What is the mistake?

Rights in AndroidManifest:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

The code I use to work with Wifi:

WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    wifiManager.startScan();
    List<ScanResult> availNetworks = wifiManager.getScanResults();
    Log.d("STRING",Integer.toString(availNetworks.size()));
    if (availNetworks.size() > 0) {
        for (int i=0; i< availNetworks.size();i++) {
            String buf = availNetworks.get(i).toString();
            String[] buflist = buf.split(",");
            Log.d("STRING","In");
            String elementWssid = buflist[0];
            String elementWsec = buflist[2];
            String elementWlevel = buflist[3];
            String SSID = elementWssid.split(": ")[1];
            String Sec = elementWsec.split(": ")[1];
            String level = elementWlevel.split(": ")[1];
            Log.d("STRING",SSID);
            Log.d("STRING",Sec);
            Log.d("STRING",level);
        }
    }

Permits have already been issued.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
DmitrySem
  • 1
  • 1
  • there's already a [question like this](https://stackoverflow.com/q/18741034/8099601) – Nitzan Daloomy Apr 13 '22 at 11:34
  • Unfortunately, this is not a solution to the problem. Only one network is visible: AndroidWifi. – DmitrySem Apr 13 '22 at 15:47
  • Solved a problem. In the application settings there is such a section as "other permissions". It contains permissions to work with wi-fi, which by default are in the "ask" status, after changing the status to "allow" the problem was solved. For some reason, android doesn't feel the need to ask for permissions like location. – DmitrySem Apr 20 '22 at 09:00
  • Great (: I'd suggest you posted this as an answer and accept it, so other people facing the problem will see what solved it for you. – Nitzan Daloomy Apr 20 '22 at 10:04

1 Answers1

0

Solved a problem. In the application settings there is such a section as "other permissions". It contains permissions to work with wi-fi, which by default are in the "ask" status, after changing the status to "allow" the problem was solved. For some reason, android doesn't feel the need to ask for permissions like location.

P.s. Xiaomi has a separate slider to access the location of ALL apps, it needs to be turned on to give permissions.

AndroidWifi on a virtual device is a test network for checking the performance of applications, since it does not know how to work with real networks.

DmitrySem
  • 1
  • 1