获取和改变Android手机网络状态的代码实现

分享到:

一、判断WIFI或者GPRS是否打开

import android.net.wifi.WifiManager;

public boolean isNetConnected(Context context) {
	ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
	if(connManager!=null){ 	
			State wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
			State gprs = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
			if(wifi == State.CONNECTED || gprs == State.CONNECTED){
			return true;
		}
	}
}
昵    称:
验证码:

相关文档: