6

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!

Ahmad Idrees
  • 181
  • 3
  • 12

1 Answers1

7

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());
Amanullah Asraf
  • 376
  • 4
  • 9
  • The WifiNetworkSpecifier works for peer to peer connections and disconnects after the operation you binded to the process gets done. – aguiarroney Jul 07 '22 at 14:42