【发布时间】:2019-10-07 09:47:26
【问题描述】:
我正在创建一个应连接到已知可用隐藏 Wi-Fi 网络的 Android 应用程序。
处理这种情况的正确方法是什么?
我已经尝试连接到隐藏的 wifi 网络。我在操作系统版本为 6.0、7.0、7.1.1、8.0 的 Android 设备上进行了尝试,但未能成功。
fun initiateWifiConnectivity(mContext: Context, sSID: String, password: String) {
mWifiManager = mContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
if (!mWifiManager!!.isWifiEnabled) {
mWifiManager!!.isWifiEnabled = true
}
mWifiConfiguration = WifiConfiguration()
mWifiConfiguration!!.SSID = convertToQuotedString(sSID)
mWifiConfiguration!!.preSharedKey = password
mWifiConfiguration!!.status = WifiConfiguration.Status.ENABLED
mWifiConfiguration!!.hiddenSSID = true
mWifiConfiguration!!.allowedAuthAlgorithms.
set(WifiConfiguration.AuthAlgorithm.LEAP)
mWifiConfiguration!!.allowedGroupCiphers.
set(WifiConfiguration.GroupCipher.TKIP)
mWifiConfiguration!!.allowedGroupCiphers.
set(WifiConfiguration.GroupCipher.CCMP)
mWifiConfiguration!!.allowedGroupCiphers.
set(WifiConfiguration.GroupCipher.WEP40)
mWifiConfiguration!!.allowedKeyManagement.
set(WifiConfiguration.KeyMgmt.WPA_PSK)
mWifiConfiguration!!.allowedKeyManagement.
set(WifiConfiguration.KeyMgmt.WPA_EAP)
mWifiConfiguration!!.allowedKeyManagement.
set(WifiConfiguration.KeyMgmt.IEEE8021X)
mWifiConfiguration!!.allowedPairwiseCiphers.
set(WifiConfiguration.PairwiseCipher.TKIP)
mWifiConfiguration!!.allowedPairwiseCiphers.
set(WifiConfiguration.PairwiseCipher.CCMP)
mWifiConfiguration!!.allowedPairwiseCiphers.
set(WifiConfiguration.PairwiseCipher.NONE)
mWifiConfiguration!!.allowedProtocols.
set(WifiConfiguration.Protocol.RSN)
mWifiConfiguration!!.allowedProtocols.
set(WifiConfiguration.Protocol.WPA)
mWifiManager!!.addNetwork(mWifiConfiguration!!)
Handler().postDelayed(Runnable {
val list = mWifiManager!!.configuredNetworks
for (i in list) {
if (i.SSID != null && i.SSID ==
convertToQuotedString(sSID)) {
mWifiManager!!.disconnect()
mWifiManager!!.enableNetwork(i.networkId, true)
mWifiManager!!.reconnect()
break
}
}
}, 15000)
}
【问题讨论】:
-
@NikunjParadva 我已经尝试过了,但没有连接。会检查
-
@AhamedMujeeb 你找到解决方案了吗?可以分享一下吗?
-
@AnantShah 尚无解决方案。存在需求。暂时使 wifi 成为硬件级别的可见 wifi 以继续工作。
标签: java android kotlin android-wifi