我指的是设备连接到接入点但由于某种原因被阻止使用此AP访问互联网的情况。
答案 0 :(得分:1)
用于检查wifi是否已启用
WifiManager wfManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
if(wfManager.isWifiEnabled())
{
//Code
}
else
{
//Code
}
检查互联网连接..
public boolean isOnline()
{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting())
{
//Try This
int i =netInfo.getType() ;
System.out.println("Net Type ="+i);
return true;
}
return false;
}
答案 1 :(得分:0)
private boolean connectionAvailable() {
boolean connected = false;
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
//we are connected to a network
connected = true;
}
return connected;
}
答案 2 :(得分:0)