私のアプリには、ネットワーク選択画面があります。これには、構成された非表示の SSID を含む、すべての可視ネットワークが表示されます。
ただし、ユーザーが非表示の SSID ではない可視ネットワークを選択し、次のコードを使用してそれに関連付ける場合。
public boolean associate(ScanResultWrapper scanResult){
WifiConfiguration wc = getWifiConfiguration(scanResult.scanResult);
int id = -1;
if (wc == null ) {
wc = new WifiConfiguration();
wc.SSID = "\"" + scanResult.SSID + "\"";
wc.BSSID = scanResult.scanResult.BSSID;
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
id = mWifiManager.addNetwork(wc);
if (!mWifiManager.saveConfiguration()){
return false;
}
} else{
id = wc.networkId;
}
boolean result;
try {
result = mWifiManager.enableNetwork(id, true);
return result;
} catch (Throwable t) {
t.printStackTrace();
return false;
}
}
したがって、ここに示すネットワークに関連付ける方法 http://developer.android.com/reference/android/net/wifi/WifiManager.html#enableNetwork(int , boolean)
mWifiManager.enableNetwork(id, true);
他のすべての構成を無効にします。これは、非表示の SSID では問題ありませんが、非表示の SSID 設定が無効になっており、スキャン結果に含まれていないことを意味します。つまり、ユーザーが非表示のネットワークにいて、別のネットワークに参加した場合、デバイスの Wifi 設定を起動しない限り、元の非表示のネットワークに戻ることはできません。
プログラムで Wifi ネットワークを変更する上記の方法は、デバイスの Wifi 設定で使用される方法とは異なる必要があることがわかりました。プログラムで関連付けてから Wifi 設定画面に移動すると、他のすべての構成済みネットワークが「無効」に設定されていることがわかります。ただし、デバイスの Wifi 設定画面からネットワークに関連付けると、他のすべての Wifi 構成は「保存済み」のままになります。
非表示の SSID 構成を無効にせずに保持するネットワークにプログラムで関連付ける代替方法はありますか?
ありがとう、これは本当の痛みです。