【问题标题】:Can I connect a wifi only one time?我可以只连接一次wifi吗?
【发布时间】:2019-05-31 07:22:02
【问题描述】:

我像这样在我的应用程序中以编程方式连接 wifi

private void WPA(String networkSSID, String networkPass, WifiManager wifiManager, String command) {
    WifiConfiguration wc = new WifiConfiguration();
    wc.SSID = "\"" + networkSSID + "\"";
    wc.preSharedKey = "\"" + networkPass + "\"";
    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);
    if (command.equals(ADD)) {
        addNetwork(wifiManager, wc);
    } else if (command.equals(REMOVE)) {
        removeNetwork(wifiManager, wc);
    }

}

private void addNetwork(WifiManager wifiManager, WifiConfiguration wc) {
    if (!wifiManager.isWifiEnabled()) enableWifi();
    int id = wifiManager.addNetwork(wc);
    if (id > -1) {
        wifiManager.disconnect();
        wifiManager.enableNetwork(id, true);
        wifiManager.reconnect();
        wifiManager.saveConfiguration();
    }
}

我想知道在Android中是否可以在不保存密码的情况下连接wifi,当wifi断开连接时,用户不输入密码就无法再次连接?如果可能的话,我怎样才能以编程方式做到这一点?

【问题讨论】:

  • 我认为您需要找出密码保存在 android 中的 wifi 连接位置,然后使用您的程序清除它。

标签: java android wifi wifimanager


【解决方案1】:

看看这个帖子how to extract wifi pass

然后在您的程序中修改它以删除所需的配置并将其保存回来。

【讨论】:

    猜你喜欢
    • 2018-10-01
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多