• 怎么判断是否有网络链接


    public boolean isNetworkAvailable(Activity activity)
    	    {
    	        Context context = activity.getApplicationContext();
    	        // 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理)
    	        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    	        
    	        if (connectivityManager == null)
    	        {
    	            return false;
    	        }
    	        else
    	        {
    	            // 获取NetworkInfo对象
    	            NetworkInfo[] networkInfo = connectivityManager.getAllNetworkInfo();
    	            
    	            if (networkInfo != null && networkInfo.length > 0)
    	            {
    	                for (int i = 0; i < networkInfo.length; i++)
    	                {
    	                    System.out.println(i + "===状态===" + networkInfo[i].getState());
    	                    System.out.println(i + "===类型===" + networkInfo[i].getTypeName());
    	                    // 判断当前网络状态是否为连接状态
    	                    if (networkInfo[i].getState() == NetworkInfo.State.CONNECTED)
    	                    {
    	                        return true;
    	                    }
    	                }
    	            }
    	        }
    	        return false;
    	    }
    

      调用上面这个函数即可

  • 相关阅读:
    赛孚耐(SafeNet)加密狗 C#调用代码
    转 RMAN-20033
    MyBatis <foreach>
    MySQL InnoDB锁问题
    MySQL MyISAM表锁
    MySQL锁概述
    MySQL 优化表数据类型
    MySQL 优化分页思路
    MySQL EXPLAIN
    MySQL 开启慢查询日志
  • 原文地址:https://www.cnblogs.com/caimuqing/p/5894115.html
Copyright © 2020-2023  润新知