转:Android检查设备是否联网

Posted QinXiao.Shou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了转: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 }  

 

以上是关于转:Android检查设备是否联网的主要内容,如果未能解决你的问题,请参考以下文章