网站建设资讯

NEWS

网站建设资讯

Android通过代码自动连接WiFi

// wc.SSID = "\"" + scanRet.SSID + "\"";

在玉州等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站制作、网站设计 网站设计制作定制网站设计,公司网站建设,企业网站建设,成都品牌网站建设,全网营销推广,成都外贸网站制作,玉州网站建设费用合理。

void connect() {

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

WifiConfiguration wc = new WifiConfiguration();

String SSID = "qvtest";

String key = "12345678";

wc.SSID = "\"" + SSID + "\""; // wifi名称

wc.preSharedKey = "\"" + key + "\""; // wifi密码

wc.hiddenSSID = true;

wc.status = WifiConfiguration.Status.ENABLED;

wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);

wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);

wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);

wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);

wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);

wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);

int res = wifi.addNetwork(wc);

boolean b = wifi.enableNetwork(res, false);

Toast.makeText(WiFiActivity.this, "res = " + res + "\n" + b + "",

Toast.LENGTH_LONG).show();

}


当前名称:Android通过代码自动连接WiFi
本文网址:http://njwzjz.com/article/johoph.html