`
wanghuihui513
  • 浏览: 5362 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

android中判断网络和WIFI是否连接

阅读更多

在android中,如何判断网络是否连接或WIFI已连接呢,很简单,可以用如下的方法判断

Java代码 复制代码
  1. public static boolean checkNetworkConnection(Context context)   
  2.    {   
  3.        final ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);   
  4.   
  5.        final android.net.NetworkInfo wifi =connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);   
  6.        final android.net.NetworkInfo mobile =connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);   
  7.   
  8.        if(wifi.isAvailable()||mobile.isAvailable())   
  9.            return true;   
  10.        else  
  11.            return false;   
  12.    }  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics