本文介绍了Wificonfiguration 已弃用 Android 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Wifi 配置29 Android 版本弃用.我想使用 WIFI 共享文件,但没有可以用于此目的的库.因此,如果有人对此问题有解决方案,请分享.

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);

有没有 WifiConfiguration 的替代方案,我可以使用它!

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

推荐答案

WifiConfiguration 在 API 级别 29 中已弃用.现在,WifiNetworkSpecifier.Builder 解决了我的问题.

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());

这篇关于Wificonfiguration 已弃用 Android 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 08:44