Connectivity Manage 휴대폰의 네트워크 유형 검색

1190 단어 모바일 개발
키 코드는 다음과 같습니다.
public String getCurrentNetType() {
		
		ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = cm.getActiveNetworkInfo();
		
		if (info == null) {
			type = "null";
		} 
		if (info.getType() == ConnectivityManager.TYPE_WIFI) {
			type = "wifi";
		} 
		if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
			int subType = info.getSubtype();
			if (subType == TelephonyManager.NETWORK_TYPE_CDMA
					|| subType == TelephonyManager.NETWORK_TYPE_GPRS
					|| subType == TelephonyManager.NETWORK_TYPE_EDGE) {
				type = "2g";//      2G GPRS EGDE,   2G CDMA
			} else if (subType == TelephonyManager.NETWORK_TYPE_UMTS
					|| subType == TelephonyManager.NETWORK_TYPE_HSDPA
					|| subType == TelephonyManager.NETWORK_TYPE_EVDO_A
					|| subType == TelephonyManager.NETWORK_TYPE_EVDO_0
					|| subType == TelephonyManager.NETWORK_TYPE_EVDO_B) {
				type = "3g";//   3G UMTS HSDPA    3G EVDO
			} else if (subType == TelephonyManager.NETWORK_TYPE_LTE) {// LTE 3g 4g   , 3.9G     
				type = "4g";
			}
		}
		return type;
	}

좋은 웹페이지 즐겨찾기