作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个 Android 应用程序,它应该连接到已知可用的隐藏 Wi-Fi 网络。
处理这种情况的正确方法是什么?
我已经尝试连接到一个隐藏的 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)
}
最佳答案
我在 Android Studio 中连接了一个隐藏的 WIFI 网络和一个 Android 7.0 设备。把 conf.hiddenSSID = true;对象 WifiConfiguration,连接网络的配置类似于一个显着的网络。
public class ShowActivity extends AppCompatActivity {
private WifiManager wifiManager; // Here is defined the instance
WifiConfiguration conf = new WifiConfiguration();
Log.d("Aut", Net + " : " + Pw);
conf.SSID = "\"" + Net + "\"";
conf.preSharedKey = "\"" + Pw + "\"";
conf.hiddenSSID = true; // Put this line to hidden SSID
conf.status = WifiConfiguration.Status.ENABLED;
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
conf.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
conf.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
// Connect Network
this.wifiManager =(WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
assert wifiManager != null;
int netId = this.wifiManager.addNetwork(conf);
WifiInfo wifi_inf = this.wifiManager.getConnectionInfo();
this.wifiManager.disableNetwork(wifi_inf.getNetworkId());
this.wifiManager.enableNetwork(netId, true);
this.wifiManager.reconnect();
}
关于java - 以编程方式连接到 Android 中的隐藏 Wi-Fi 网络?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56230831/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!