转:Android检查设备是否联网

 1 public static boolean isConnect(Context context) {  
 2     ConnectivityManager connectionManager = (ConnectivityManager) context  
 3             .getSystemService(Context.CONNECTIVITY_SERVICE);  
 4     if (connectionManager != null) {  
 5         NetworkInfo info = connectionManager.getActiveNetworkInfo();  
 6         if (info != null && info.isConnected()) {  
 7             if (info.getState() == NetworkInfo.State.CONNECTED) {  
 8                 return true;  
 9             }  
10         }  
11     }  
12     return false;  
13 }  

 

posted @ 2017-05-16 20:47  QinXiao.Shou  阅读(211)  评论(0编辑  收藏  举报