2

私は、wifiを自動的かつ定期的に有効にし、ネットワークをスキャンし、開いているネットワークをフィルターで除外し(パスは不要)、wifiConfigurationオブジェクトを作成し、それを使用してそのネットワークに接続するアプリケーションを開発しています。

私はAndroid開発者のwifiConfigurationAPIを読みました。そしてそれに基づいて、wifiを有効にし、ネットワークをスキャンして結果を次のようなリストに保存するコードのサンプルを作成しました。

11-25 16:05:44.191: I/WIFISCAN(12955): List of networks: [SSID: airlive_w, BSSID: 00:4f:62:2c:96:18, capabilities: [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS], level: -71, frequency: 2432, SSID: Mikynet, BSSID: 00:1e:2a:ed:62:4e, capabilities: [WPA2-PSK-CCMP], level: -72, frequency: 2427, SSID: TP-LINK_Vectra, BSSID: 74:ea:3a:ab:eb:b0, capabilities: [WPA2-PSK-TKIP+CCMP][WPS], level: -73, frequency: 2462, SSID: Nasza Siec- ryby, BSSID: d8:5d:4c:df:60:74, capabilities: [WPA2-PSK-TKIP+CCMP-preauth], level: -88, frequency: 2437, SSID: lanzarote, BSSID: 00:27:19:f7:05:9c, capabilities: [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP-preauth], level: -89, frequency: 2437, SSID: Alicja, BSSID: 94:44:52:a7:17:02, capabilities: [WPA-PSK-CCMP][WPA2-PSK-CCMP][WPS], level: -89, frequency: 2442, SSID: orangebox, BSSID: 00:1f:f3:f8:ea:0f, capabilities: [WPA2-PSK-CCMP], level: -89, frequency: 2462]

その結果が得られたら、どの方法が開いているか(パスフリー)を知ることができますか?そして、開いているもののwifiConfigurationを作成するにはどうすればよいですか?

WPA-PSKのwifiConfigurationのサンプルは次のとおりです。

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wc = new WifiConfiguration();
// This is must be quoted according to the documentation 
// http://developer.android.com/reference/android/net/wifi/WifiConfiguration.html#SSID
wc.SSID = "\"SSIDName\"";
wc.preSharedKey  = "\"password\"";
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);
Log.d("WifiPreference", "add Network returned " + res );
boolean b = wifi.enableNetwork(res, true);        
Log.d("WifiPreference", "enableNetwork returned " + b );

どんなガイダンスも高く評価されます!:)

4

1 に答える 1

2

私の知る限り、Wifiサービスにオープン構成を追加してみる必要があるかもしれません。オープンネットワークの追加に失敗した場合は、おそらく何らかの認証プロトコルが必要です。

WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "some ssid from the list";
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
int networkId = wifi.addNetwork(wc);
if (networkId == -1) {
    // probably not open
} else {
    // likely open
}

これをメソッドと組み合わせて使用​​して、getConfiguredNetworks近くのネットワークがa)以前に接続されていてb)開いているかどうかを確認することもできます。

于 2011-11-25T18:58:31.600 に答える