我的应用程序是在android中使用wifi管理器,但是在情况出现的情况下我遇到了错误:: WIFI已打开但是当时我的应用程序没有通过身份验证(使用我们公司的wifi用户名和密码)是强行关闭,
我正在使用的代码是
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");
}
答案 0 :(得分:1)
SupplicantState supState;
wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
supState = wifiInfo.getSupplicantState();
请参阅this answer in stackoverflow
如果COMPLETED - All authentication completed.
答案 1 :(得分:1)
答案 2 :(得分:0)
不要使用
conectivityManager.getNetworkInfo(0) and getNetworkInfo(1).
而不是使用
用于WiFi
NetworkInfo conectivityManager = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
适用于移动网络(3g)
NetworkInfo conectivityManager = connectivity.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
果冻豆的原因会给这样的硬编码带来麻烦。