15

I'm currently migrating my application to Android Q. I want to list all configured WiFi networks and before Q I was able to do so with the function getConfiguredNetworks from the WiFiManager. Sadly this method was deprecated on API level 29 and returns an empty list on Android Q devices.

The deprecation comment only refers to cases where I also want to connect to these networks. I do not want to do this, I just want to list the networks with their name and get their internal id. Do you have any ideas how I should do this in Q?

Cilenco
  • 6,951
  • 17
  • 72
  • 152
  • 1
    documentaion at https://developer.android.com/reference/android/net/wifi/WifiManager says This method was deprecated in API level 29. a) See WifiNetworkSpecifier.Builder#build() for new mechanism to trigger connection to a Wi-Fi network. – Pemba Tamang Aug 08 '19 at 10:35
  • 1
    I do not want to connect to a network, just list all configured ones with their name – Cilenco Aug 08 '19 at 10:36
  • 1
    have you given location permissions? – Pemba Tamang Aug 08 '19 at 11:05
  • Is it possible to enable wifi on API 29? Can someone please check and answer on https://stackoverflow.com/questions/58075918/how-to-programatically-enable-wifi-on-android-10-devices ? – AdeleGoldberg Sep 24 '19 at 08:45
  • See "[Restrictions on direct access to configured Wi-Fi networks](https://developer.android.com/about/versions/10/privacy/changes#configure-wifi)" in the Android 10 documentation. – JJD Nov 11 '20 at 13:51

2 Answers2

0

I guess there is No way to get Configured WiFi Networks in Android Q and Above. The only is to get the currently available networks using getScanResults() I know this wont actually solve the issue for getting the configured network names. Instead only gets the currently available networks.

    List<ScanResult> results = null;
    TextView outputs = (TextView)findViewById(R.id.outputs);
    try{
        WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
        results = wifiManager.getScanResults();
        int len = results.size();
        String res = null;
        for (int i = 0; i < len; i++) {
            res = outputs.getText() + "\n" + results.get(i).SSID;
            outputs.setText(res);

        }

    }
    catch(Exception e)
    {
        Log.e("MainActivity",e.getMessage());
    }

Currently they are only providing mechanism to trigger connection to a WiFi Network as per their documentations. Lets hope something comes up or not

Paul P Joby
  • 713
  • 7
  • 17
  • Thanks for clarifying that there is no way...Android is getting too sandboxed. I am trying to just notify the user that they've lost connection a particular wifi device. But the Apis above 26 are getting so limited with wireless control. – TwoFingerRightClick Mar 30 '21 at 00:04
0

i had the same problem, and my problem was that I has mi targetSdkVersion in 30! and the function getConfiguredNetworks was deprecated in api 29, when I run my app in a android 9 devices or below, works great but when I run my app into android 10, the function getConfiguredNetworks return null or empty list, my solution was change my targetSdkVersion to 28, like this

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.0"

    defaultConfig {
        applicationId "asdaadsda"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

References: https://developer.android.com/reference/android/net/wifi/WifiManager#getConfiguredNetworks()

Matt Ke
  • 3,599
  • 12
  • 30
  • 49