2011-04-30 107 views

回答

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; 
} 
+0

這不正是我所需要的 - 國有關的WiFi連接意味着該設備被連接到AP,但並不那麼你要檢查無線網絡連接,訪問一定能夠訪問互聯網 – Asahi 2011-04-30 09:21:15

+0

ok了互聯網與否。我不知道這一點。 – Dharmendra 2011-04-30 09:26:26

+0

感謝您的時間! – Asahi 2011-05-03 18:01:24

1

用於檢查無線網絡連接啓用與否

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; 

} 
+0

這不完全是我所需要的 - 狀態連接的WiFi連接意味着設備連接到AP,但不一定可以訪問互聯網 – Asahi 2011-04-30 09:29:20

+0

是的,我知道它.... – 2011-04-30 09:39:26

+0

看到我的編輯答案 – 2011-04-30 09:43:03

相關問題