第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在無線模式存在的情況下,如何連接無線網(wǎng)絡(luò)

在無線模式存在的情況下,如何連接無線網(wǎng)絡(luò)

qq_遁去的一_1 2019-03-19 17:15:06
我使用下面的代碼在android手機上創(chuàng)建一個無線模式。出于某種原因它每次都會創(chuàng)建一個新模式,因此對于相同的無線網(wǎng)絡(luò)手機將會有多個模式。是否有辦法能實現(xiàn)當一個模式已經(jīng)存在時,就不要再創(chuàng)建一個新的模式?public class IVMOBILEActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);     TextView tv = new TextView(this);            TextView status = new TextView(this);                       WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);      WifiConfiguration wc = new WifiConfiguration();       wc.SSID = "\"MyNetwork\""; //IMP! This should be in Quotes!!      wc.hiddenSSID = true;      wc.status = WifiConfiguration.Status.ENABLED;           wc.priority = 10;      wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);      wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);       wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);      wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);      wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);      wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);      wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);      wc.preSharedKey = "\"Password\"";      WifiManager  wifiManag = (WifiManager) this.getSystemService(WIFI_SERVICE);      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);         Log.d("WifiPreference", "enableNetwork returned " + b );        tv.setText("You are now connected!  " +             "Version 1.0");     status.setText("The was an error connecting, please try again.");     try {         Thread.sleep(5000);          ConnectivityManager connec = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
查看完整描述

2 回答

?
收到一只叮咚

TA貢獻1821條經(jīng)驗 獲得超5個贊

public WifiConfiguration checkPreviousConfiguration(WifiConfiguration wc) {
    List<WifiConfiguration configs = wifi.getConfigurations();
    for(WifiConfiguration config : configs) {
        if(config.SSID.equals(wc.SSID)) return config;
    }
    return wc;
}

//......
int res = wifi.addNetwork(checkPreviousConfiguration(wc));


查看完整回答
反對 回復(fù) 2019-04-26
?
暮色呼如

TA貢獻1853條經(jīng)驗 獲得超9個贊

int res = wifi.addNetwork(wc); 三星手機測試發(fā)現(xiàn),返回-1 LZ 請教一下


查看完整回答
反對 回復(fù) 2019-04-26
  • 2 回答
  • 0 關(guān)注
  • 487 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號