ネットワーク (WPA2-PSK) を構成して追加できますが、(WifiManager.enableNetwork を使用して) 有効にしようとすると失敗します。呼び出し間のログに役立つデバッグ情報はありません ( 以外W/ActivityManager﹕ Activity idle timeout
)。これは何ですか?
コードは次のとおりです。
String quotedSSID = "\"" + networkSSID + "\"";
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = quotedSSID;
conf.preSharedKey = "\""+ networkPass +"\"";
conf.hiddenSSID = true;
conf.allowedProtocols.set(WifiConfiguration.Protocol.RSN); // For WPA2
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
Log.w(MainActivity.APP_TAG, "Adding " + conf.SSID);
int networkId = wifiManager.addNetwork(conf);
if (networkId < 0) {
Log.e(MainActivity.APP_TAG, "Failed to configure " + conf.SSID);
}
if (!wifiManager.enableNetwork(conf.networkId, true)) {
Log.e(MainActivity.APP_TAG, "Failed to enable " + conf.SSID);
} else {
Log.i(MainActivity.APP_TAG, "Enabled " + conf.SSID);
}