Wificonfiguration is deprecated Android 10
Asked Answered
A

1

8

Wifi configuration is deprecated at 29 Android Version. I want to share the file using WIFI but there is no such library which i can use for this purpose. So If Anybody has a solution for this problem kindly share it.

WifiConfiguration wc = new WifiConfiguration(); 
wc.SSID = "\"SSID_NAME\""; //IMP! This should be in Quotes!!
wc.hiddenSSID = true;
boolean res1 = wifiManag.setWifiEnabled(true);
int res = wifi.addNetwork(wc);
Log.d("WifiPreference", "add Network returned " + res );
boolean es = wifi.saveConfiguration();
Log.d("WifiPreference", "saveConfiguration returned " + es );
boolean b = wifi.enableNetwork(res, true); 

Is there any alternative for WifiConfiguration which i can use it!

Auberon answered 22/7, 2020 at 11:23 Comment(0)
G
10

WifiConfiguration was deprecated in API level 29. Now, WifiNetworkSpecifier.Builder solve my problem.

WifiNetworkSpecifier wifiNetworkSpecifier = new WifiNetworkSpecifier.Builder()
            .setSsid(ssid)
            .setWpa2Passphrase(password)
            .build();
NetworkRequest networkRequest = new NetworkRequest.Builder()
            .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
            .setNetworkSpecifier(wifiNetworkSpecifier)
            .build();
ConnectivityManager connectivityManager = (ConnectivityManager)this.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
connectivityManager.requestNetwork(networkRequest, new ConnectivityManager.NetworkCallback());
Gongorism answered 17/8, 2020 at 18:33 Comment(1)
The WifiNetworkSpecifier works for peer to peer connections and disconnects after the operation you binded to the process gets done.Roswell

© 2022 - 2024 — McMap. All rights reserved.