首页 > 代码库 > 检查网络是否可用
检查网络是否可用
/** * 检测网络是否可用1 * @param act * @return */ public boolean isNetConnected(Activity act){ ConnectivityManager manager = (ConnectivityManager) act .getApplicationContext().getSystemService( Context.CONNECTIVITY_SERVICE); if (manager == null) { return false; } NetworkInfo networkinfo = manager.getActiveNetworkInfo(); if (networkinfo == null || !networkinfo.isAvailable()) { return false; } return true; } /** * 检测网络是否可用2 */ private boolean isNetConnected() { PppoeManager pppoeManager = PppoeManager.getInstance(); EthernetManager ethernetManager = EthernetManager.getInstance(); ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getNetworkInfo (ConnectivityManager.TYPE_WIFI); if (networkInfo.isConnected() || ethernetManager.isNetworkConnected() || pppoeManager.getPppoeStatus().equals (PppoeManager.PPPOE_STATE_CONNECT)) { return true; } else { return false; } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。