wujushan 2018-01-16 02:15 采纳率: 0%
浏览 1744
已结题

怎么在Android6.0上连接一个无密码wifi

使用网上的一些demo,连接总是会失败,比如下面两段代码都会失败:

       val config = WifiConfiguration()
        config.allowedAuthAlgorithms.clear()
        config.allowedGroupCiphers.clear()
        config.allowedKeyManagement.clear()
        config.allowedPairwiseCiphers.clear()
        config.allowedProtocols.clear()
        config.SSID = "\"" + SSID + "\""
        val tmpConfig = isExsits(ssid)
        if (tmpConfig != null) {
            mWifiManager.removeNetwork(tmpConfig.networkId)
        }
        if (Type == WifiCipherType.WIFICIPHER_NOPASS) {
                //Password为空字符
            config.wepKeys[0] = "\"" + Password + "\""
            config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE)
            config.wepTxKeyIndex = 0
        }
        val config = WifiConfiguration()
        config.allowedAuthAlgorithms.clear()
        config.allowedGroupCiphers.clear()
        config.allowedKeyManagement.clear()
        config.allowedPairwiseCiphers.clear()
        config.allowedProtocols.clear()
        config.SSID = "\"" + SSID + "\""
        val tmpConfig = isExsits(ssid)
        if (tmpConfig != null) {
            mWifiManager.removeNetwork(tmpConfig.networkId)
        }
        if (Type == WifiCipherType.WIFICIPHER_NOPASS) {
            config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE)
        }
  • 写回答

2条回答 默认 最新

  • JohnwayChan 2018-01-16 02:31
    关注

    在manifest中声明user-permission了吗

    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决