首页 > 代码库 > android判断是否连接wifi和网络状态的判断

android判断是否连接wifi和网络状态的判断


<span style="font-size:18px;">// 是否连接WIFI
	public static boolean isWifiConnected(Context context) {
		ConnectivityManager connectivityManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo wifiNetworkInfo = connectivityManager
				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		if (wifiNetworkInfo.isConnected()) {
			return true;
		}
		return false;
	}

	/**
	 * 对网络连接状态进行判断
	 * 
	 * @return true, 可用; false, 不可用
	 */
	public static boolean isOpenNetwork(Context ctx) {
		ConnectivityManager connManager = (ConnectivityManager) ctx
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (connManager.getActiveNetworkInfo() != null) {
			return connManager.getActiveNetworkInfo().isAvailable();
		}
		return false;
	}</span>


android判断是否连接wifi和网络状态的判断