[英]Android:How can I check if wifi authenticated or not
My application is using wifi manager in android, but I am facing an error in a situation the situation is::WIFI is turned on but it is not authenticated(with our company wifi user name and password)at that time my application is force closing, 我的应用程序是在android中使用wifi管理器,但我遇到一个错误,情况是这样的情况:: WIFI已打开,但它未经过身份验证(使用我们公司的wifi用户名和密码),那时我的应用程序正在关闭,
code I am using is 我正在使用的代码是
try{
if (connectivityManager != null &&
(connectivityManager.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED) ||
(connectivityManager.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED))
{
//You are connected, do something online.
return true;
}
else if (connectivityManager.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED ||
connectivityManager.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED )
{
//Not connected.
//Toast.makeText(getApplicationContext(), "You must be connected to the internet", Toast.LENGTH_LONG).show();
loginTask.myPublishProgress("You must be connected to the internet");
return false;
}
}
catch(NullPointerException ae)
{
ae.printStackTrace();
loginTask.myPublishProgress("You must be connected to the internet");
}
Use SupplicantState 使用SupplicantState
SupplicantState supState;
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
supState = wifiInfo.getSupplicantState();
See this answer in stackoverflow 在stackoverflow中查看此答案
If COMPLETED - All authentication completed.
如果
COMPLETED - All authentication completed.
Hi check the below answers: 嗨检查以下答案:
How to detect when WIFI Connection has been established in Android? 如何检测Android中何时建立WIFI连接?
How do I see if Wi-Fi is connected on Android? 如何查看Android上是否连接了Wi-Fi?
Don't use 不要用
conectivityManager.getNetworkInfo(0) and getNetworkInfo(1).
Instead of that use 而不是那种用途
For WiFi 适用于WiFi
NetworkInfo conectivityManager = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
For mobile networks(3g) 适用于移动网络(3g)
NetworkInfo conectivityManager = connectivity.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
Cause on Jelly Beans will make trouble hardcoding values like that. 果冻豆的原因会给这样的硬编码值带来麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.