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");
}
3 个解决方案
#1
1
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?
#2
1
Use SupplicantState
SupplicantState supState;
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
supState = wifiInfo.getSupplicantState();
See this answer in *
在*中查看此答案
If COMPLETED - All authentication completed.
如果已完成 - 所有身份验证均已完成。
#3
0
Don't use
conectivityManager.getNetworkInfo(0) and getNetworkInfo(1).
Instead of that use
而不是那种用途
For 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.
果冻豆的原因会给这样的硬编码值带来麻烦。
#1
1
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?
#2
1
Use SupplicantState
SupplicantState supState;
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
supState = wifiInfo.getSupplicantState();
See this answer in *
在*中查看此答案
If COMPLETED - All authentication completed.
如果已完成 - 所有身份验证均已完成。
#3
0
Don't use
conectivityManager.getNetworkInfo(0) and getNetworkInfo(1).
Instead of that use
而不是那种用途
For 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.
果冻豆的原因会给这样的硬编码值带来麻烦。